2
2
# # functions do
3
3
4
4
# # Write a short comment describing this function
5
+ # ##The first function, makeCacheMatrix creates a special "matrix"
6
+ # ##which is really a list containing a function to
7
+ # ##*set the value of the matrix
8
+ # ##*get the value of the matrix
9
+ # ##*set the value of the inverse
10
+ # ##*get the value of the inverse
5
11
6
12
makeCacheMatrix <- function (x = matrix ()) {
7
-
13
+ m <- NULL
14
+ set <- function (y ) {
15
+ x <<- y
16
+ m <<- NULL
17
+ }
18
+ get <- function () x
19
+ setinverse <- function (solve ) m <<- solve
20
+ getinverse <- function () m
21
+ list (set = set , get = get ,
22
+ setinverse = setinverse ,
23
+ getinverse = getinverse )
8
24
}
9
25
10
26
11
27
# # Write a short comment describing this function
28
+ # ##The following function calculates the inverse of the
29
+ # ##special "matrix" created with the above function.
30
+ # ##However, it first checks to see if the inverse has
31
+ # ##already been calculated. If so, it gets the inverse
32
+ # ##from the cache and skips the computation.
33
+ # ##Otherwise, it calculates the mean of the data and sets
34
+ # ##the value of the inverse in the cache via the setinverse function.
12
35
13
36
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
15
- }
37
+ # # Return a matrix that is the inverse of 'x'
38
+ m <- x $ getinverse()
39
+ if (! is.null(m )) {
40
+ message(" getting cached data" )
41
+ return (m )
42
+ }
43
+ data <- x $ get()
44
+ m <- solve(data , ... )
45
+ x $ setinverse(m )
46
+ m
47
+ }
0 commit comments