Skip to content

Commit e2fe0c5

Browse files
committed
Submit invered matrix assignment
1 parent 7f657dd commit e2fe0c5

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

cachematrix.R

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## Functions to cache a matrix, invert it and cache the result.
2+
## Saves the inversion from being recomputed repeatedly.
33

4-
## Write a short comment describing this function
4+
## Function to get and set matrix to be inverted
5+
## and cache the inverted result.
56

67
makeCacheMatrix <- function(x = matrix()) {
7-
8+
i <- NULL
9+
set <- function(y) {
10+
x <<- y
11+
i <<- NULL
12+
}
13+
get <- function() x
14+
setinversematrix <- function(inv) i <<- inv
15+
getinversematrix <- function() i
16+
list(set = set, get = get,
17+
setinversematrix = setinversematrix,
18+
getinversematrix = getinversematrix)
819
}
920

1021

11-
## Write a short comment describing this function
22+
## Function which determines whether or not to
23+
## compute a new inverted matrix or read an
24+
## existing on from the cache.
1225

1326
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
15-
}
27+
i <- x$getinversematrix()
28+
if(!is.null(i)) {
29+
message("getting cached data")
30+
return(i)
31+
}
32+
data <- x$get()
33+
i <- solve(data, ...)
34+
x$setinversematrix(i)
35+
i
36+
}

0 commit comments

Comments
 (0)