File tree Expand file tree Collapse file tree 1 file changed +31
-8
lines changed Expand file tree Collapse file tree 1 file changed +31
-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
+ # # This routine takes as input a matrix from the user
2
+ # # and creates a special object that can optimize matrix
3
+ # # inversion by caching results.
4
+ # # Example: sqmar
5
+ # # sqmat <- matrix(4:7,2,2)
6
+ # # cachedmat <- makeCacheMatrix(sqmat)
7
+ # # cacheSolve(cm)
5
8
9
+ # # This routine takes a matrix as input and exposes
10
+ # # routines which allow cacheSolve to fetch cached
11
+ # # inverted matrix copy, if it already exists.
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
+ setsolve <- function (solve ) m <<- solve
20
+ getsolve <- function () m
8
21
}
9
22
10
-
11
- # # Write a short comment describing this function
23
+ # # This routine takes as input a special "cachedMatrix"
24
+ # # and returns a inverted one
12
25
13
26
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
27
+ # # Return a matrix that is the inverse of 'x'
28
+ m <- x $ getsolve()
29
+ if (! is.null(m )) {
30
+ message(" getting cached matrix inversion data" )
31
+ return (m )
32
+ }
33
+ data <- x $ get()
34
+ m <- solve(data , ... )
35
+ x $ setsolve(m )
36
+ m
15
37
}
38
+
You can’t perform that action at this time.
0 commit comments