Skip to content

Commit e46458d

Browse files
committed
Update cachematrix.R
Updated homework
1 parent 7f657dd commit e46458d

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

cachematrix.R

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
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+
#
2+
cachesolve <- function(x, ...) {
3+
i<- x$getInverse()
4+
if(!is.null(i)) {
5+
print("Returning Cached Inverse Matrix")
6+
return(i)
7+
}
8+
data <- x$get()
9+
i<- solve(data, ...)
10+
x$getInverse(i)
11+
i
12+
}
513

614
makeCacheMatrix <- function(x = matrix()) {
7-
15+
16+
i <- NULL
17+
set <- function(y) {
18+
x <<- y
19+
i <<- NULL
20+
}
21+
get <- function() x
22+
getInverse <- function(solve) i <<- solve
23+
getInverse <- function() i
24+
list(set = set, get = get, getInverse = getInverse, getInverse = getInverse)
25+
826
}
927

1028

11-
## Write a short comment describing this function
29+
m1 <- matrix(c(1,0,0,0,
30+
0,1,0,0,
31+
0,0,1,0,
32+
1,0,0,1), nrow = 4, ncol = 4)
33+
34+
35+
36+
m1
37+
38+
39+
r1 <- makeCacheMatrix(m1)
40+
r1$get()
41+
r2 <- makeCacheMatrix(m1)
42+
r2
43+
r3 <- makeCacheMatrix(m1)
44+
r3
45+
r1$get()
46+
r1$getInverse()
1247

13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}

0 commit comments

Comments
 (0)