File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
6
- makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ makeCacheMatrix <- function (x = matrix ())
7
+
8
+ {
9
+ # # Check if first run
10
+ if (! exists(" cachedMatrix" )){
11
+ cachedMatrix <<- x
12
+ cachedInvMatrix <<- solve(x )
13
+ cachedInvMatrix
14
+ }else if (identical(x , cachedMatrix ) ){
15
+ # # Check if we have a cached matrix
16
+ cachedInvMatrix
17
+ }else {
18
+ # # Save the original matrix
19
+ cachedMatrix <<- x
20
+ # # Save the identity matrix
21
+ cachedInvMatrix <<- solve(x )
22
+
23
+ }
24
+ # # return the cached inverse matrix
25
+ cachedInvMatrix
26
+
8
27
}
9
28
10
29
11
30
# # Write a short comment describing this function
12
31
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
32
+ cacheSolve <- function (x , ... ){
33
+ # # Return a matrix that is the inverse of 'x'
34
+ makeCacheMatrix(x )
15
35
}
You can’t perform that action at this time.
0 commit comments