Skip to content

Commit a6cebae

Browse files
committed
finished cacheSolve and makeCacheMatrix functions
1 parent ad3f187 commit a6cebae

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

cachematrix.R

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
## Put comments here that give an overall description of what your
22
## functions do
33

4-
## Write a short comment describing this function
4+
##
5+
## This function creates a special matrix object that is then cached.
6+
## When called it creates inver
7+
##
58

69
makeCacheMatrix <- function(x = matrix()) {
7-
10+
m <- NULL
11+
set <- function(y) {
12+
x <<- y
13+
m <<- NULL
14+
}
15+
get <- function() x
16+
setmatrix <- function(solve) m <<- solve
17+
getmatrix <- function() m
18+
list(set = set, get = get,
19+
setmatrix = setmatrix,
20+
getmatrix = getmatrix)
821
}
922

1023

11-
## Write a short comment describing this function
12-
24+
##
25+
## This function checks for a cached version of the matrix
26+
## If it is not cached it computes the inverse of the matrix using the solve() function
27+
## This function assumes that the matrix is invertible (square dimensions)
28+
##
1329
cacheSolve <- function(x, ...) {
1430
## Return a matrix that is the inverse of 'x'
15-
solve(x)
31+
m <- x$getmatrix()
32+
if(!is.null(m)) {
33+
message("getting cached data")
34+
return(m)
35+
}
36+
data <- x$get()
37+
message("are we here")
38+
m <- solve(data, ...)
39+
x$setmatrix(m)
40+
m
1641
}

0 commit comments

Comments
 (0)