Skip to content

Commit 1eacc53

Browse files
committed
Update README as specified
solve
1 parent 7f657dd commit 1eacc53

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

cachematrix.R

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
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)
58

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.
612
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
821
}
922

10-
11-
## Write a short comment describing this function
23+
## This routine takes as input a special "cachedMatrix"
24+
## and returns a inverted one
1225

1326
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
1537
}
38+

0 commit comments

Comments
 (0)