Skip to content

Commit 494c5a0

Browse files
committed
Assignment2 for submission
1 parent 7f657dd commit 494c5a0

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

cachematrix.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
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 function takes an invertible matrix to return a vector that
2+
## contains functions to 1) set the value of vector, 2}get the value,
3+
## 3)set the inverse of the matrix, and 4)get the inverse.
54

65
makeCacheMatrix <- function(x = matrix()) {
7-
6+
inverse <- NULL
7+
set <- function (z) {
8+
x <<- z
9+
inverse <<- NULL
10+
}
11+
get <- function() x
12+
setInverse <- function(solve) inverse <<- solve
13+
getInverse <- function() inverse
14+
list(set = set, get = get,
15+
setInverse = setInverse, getInverse = getInverse)
816
}
917

1018

11-
## Write a short comment describing this function
19+
## This function returns the inverse of the vector created with makeCacheMtrix
20+
## by first getting it from cache if available.
1221

1322
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
23+
inverse <- x[[getInverse()]]
24+
if(!is.null(inverse)){
25+
message("getting cached data")
26+
return(inverse)
27+
}
28+
data <- x[[get()]]
29+
inverse <- solve(data, ...)
30+
x[[setInverse(inverse)]]
31+
inverse ## Return a matrix that is the inverse of 'x'
1532
}

0 commit comments

Comments
 (0)