Skip to content

Commit c53cbe3

Browse files
author
Andrew Tippey
committed
Initial assignment update
1 parent 7f657dd commit c53cbe3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

cachematrix.R

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
44
## Write a short comment describing this function
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
inv <- NULL;
8+
set <- function(updt){
9+
x <<- updt;
10+
inv <<-NULL;
11+
}
12+
get <- function() x;
13+
setInv <- function(updt_inv) inv <<- updt_inv;
14+
getInv <- function() inv;
15+
list( set = set
16+
,get = get
17+
,setInv = setInv
18+
,getInv = getInv )
819
}
920

1021

1122
## Write a short comment describing this function
1223

1324
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
25+
## Return a matrix that is the inverse of 'x'
26+
inv <- x$getInv()
27+
if( !is.null(inv) ){
28+
message( "Getting cached data" );
29+
return(inv);
30+
}
31+
data <- x$get();
32+
inv <- solve(data);
33+
x$setInv(inv);
34+
inv;
1535
}

0 commit comments

Comments
 (0)