Skip to content

Commit 425a856

Browse files
author
Stuart Woodward
committed
Initial try..w
1 parent e3abb1a commit 425a856

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cachematrix.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

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

8+
i <- NULL
9+
set <- function(y) {
10+
x <<- y
11+
<<- NULL
12+
}
13+
get <- function() x
14+
setinverse <- function(inverse) i <<- inverse
15+
getinverse <- function() i
16+
list(set = set, get = get,
17+
setinverse = setinverse,
18+
getinverse = getinverse)
19+
820
}
921

1022
## cacheSolve: This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
@@ -13,4 +25,15 @@ makeCacheMatrix <- function(x = matrix()) {
1325

1426
cacheSolve <- function(x, ...) {
1527
## Return a matrix that is the inverse of 'x'
28+
29+
i <- x$getInverse()
30+
if(!is.null(i)) {
31+
message("getting cached data")
32+
return(m)
33+
}
34+
data <- x$get()
35+
i <- solve(data, ...)
36+
x$setinverse(i)
37+
i
38+
1639
}

0 commit comments

Comments
 (0)