Skip to content

Commit 6bc6699

Browse files
committed
edit for asg 002 coursera
1 parent 7f657dd commit 6bc6699

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cachematrix.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,37 @@
55

66
makeCacheMatrix <- function(x = matrix()) {
77

8+
ainv <- NULL
9+
10+
set <- function(newMatrix)
11+
{
12+
x <<- newMatrix
13+
ainv <<- NULL
14+
}
15+
16+
get <- function() x
17+
setInv <- function(inv) ainv <<- inv
18+
getInv <- function() ainv
19+
20+
list (set=set,get=get,setInv=setInv,getInv=getInv)
21+
22+
823
}
924

1025

1126
## Write a short comment describing this function
1227

1328
cacheSolve <- function(x, ...) {
1429
## Return a matrix that is the inverse of 'x'
30+
31+
if (is.null(x$getInv()))
32+
{
33+
message("calculating Inverse ::")
34+
inv <- solve(x$get(),...)
35+
x$setInv(inv)
36+
}
37+
else
38+
message("Getting Inv from cache:")
39+
x$getInv()
40+
1541
}

0 commit comments

Comments
 (0)