8000 Updated function #4 · jpavkov/ProgrammingAssignment2@c820acf · GitHub
[go: up one dir, main page]

Skip to content

Commit c820acf

Browse files
committed
Updated function rdpeng#4
1 parent 4fe4607 commit c820acf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cachematrix.R

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ makeCacheMatrix <- function(x = matrix()) {
3131
getinverse = getinverse)
3232

3333
}
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+
}

0 commit comments

Comments
 (0)
0