File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
3
-
4
- # # Write a short comment describing this function
1
+ # # Coursera R Programming Course (rprog-007)
2
+ # # Programming Assignment 2 (Week 3)
3
+ # # Set of functions that caches the inversion of a matrix
5
4
5
+ # # makeCacheMatrix is function creates a special "matrix" object that can
6
+ # # cache its inverse.
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ # # Return a vector that is a cache of an inverse matrix
9
+ m <- NULL
10
+ set <- function (y ) {
11
+ x <<- y
12
+ m <<- NULL
13
+ }
14
+ get <- function () x
15
+ setmatrix <- function (solve ) m <<- solve
16
+ getmatrix <- function () m
17
+ list (set = set , get = get , setmatrix = setmatrix , getmatrix = getmatrix )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
12
-
21
+ # # This function computes the inverse of the special "matrix" returned by
22
+ # # makeCacheMatrix above. If the inverse has already been calculated (and the
23
+ # # matrix has not changed), then the cachesolve should retrieve the inverse
24
+ # # from the cache.
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ # # Return a matrix that is the inverse of 'x'
27
+ m <- x $ getmatrix()
28
+ if (! is.null(m )) {
29
+ message(" getting cached data" )
30
+ return (m )
31
+ }
32
+ data <- x $ get()
33
+ m <- solve(data , ... )
34
+ x $ setmatrix(m )
35
+ m
15
36
}
You can’t perform that action at this time.
0 commit comments