File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -31,3 +31,32 @@ makeCacheMatrix <- function(x = matrix()) {
31
31
getinverse = getinverse )
32
32
33
33
}
34
+
35
+
36
+
37
+ # # The cacheSolve function takes the object created from the function above and looks
38
+ # # for the inverse of the matrix. If the object already has calculated it, then it will
39
+ # # just pull in the inverse which is stored. If it doesn't already have it calculated,
40
+ # # then it will calculate the inverse.
41
+
42
+ cacheSolve <- function (x , ... ) {
43
+ # # Return a matrix that is the inverse of 'x'
44
+
45
+ im <- x $ getinverse()
46
+
47
+ # checks to see if the inverse is already calculated
48
+ if (! is.null(im )) {
49
+ message(" getting inverse matrix" )
50
+ return (im )
51
+ }
52
+
53
+ data <- x $ get()
54
+
55
+ # if not already calculated, solves for the inverse of the matrix
56
+ im <- solve(data , ... )
57
+
58
+ x $ setinverse(im )
59
+
60
+ im
61
+
62
+ }
You can’t perform that action at this time.
0 commit comments