Skip to content

Commit b025b37

Browse files
author
Brandon Kindred
committed
matrix inversion
1 parent 7f657dd commit b025b37

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cachematrix.R

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,38 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setsolve <- function(solve) m <<- solve
14+
getsolve <- function() m
15+
list(set = set, get = get,
16+
setsolve = setsolve,
17+
getsolve = getsolve)
818
}
919

1020

1121
## Write a short comment describing this function
1222

1323
cacheSolve <- function(x, ...) {
1424
## Return a matrix that is the inverse of 'x'
25+
m <- x$getsolve()
26+
if(!is.null(m)) {
27+
message("getting cached data")
28+
return(m)
29+
}
30+
data <- x$get()
31+
m <- solve(data, ...)
32+
x$setsolve(m)
33+
m
1534
}
35+
36+
mat <- matrix(1:9, ncol=3)
37+
mat = replicate(10, rnorm(10))
38+
vect <- makeCacheMatrix(mat)
39+
vect
40+
cacheSolve(vect)
41+
cacheSolve(vect)

0 commit comments

Comments
 (0)