File tree Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Expand file tree Collapse file tree 1 file changed +28
-7
lines changed Original file line number Diff line number Diff line change 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.
3
3
4
- # # Write a short comment describing this function
4
+ # # Function to get and set matrix to be inverted
5
+ # # and cache the inverted result.
5
6
6
7
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 )
8
19
}
9
20
10
21
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.
12
25
13
26
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
+ }
You can’t perform that action at this time.
0 commit comments