Skip to content

Commit 0574b77

Browse files
David BoekeDavid Boeke
authored andcommitted
Finished Prog Assignment 2
1 parent 7f657dd commit 0574b77

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

cachematrix.R

Lines changed: 29 additions & 8 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
3-
4-
## Write a short comment describing this function
1+
## Coursera R Programming Course (rprog-007)
2+
## Programming Assignment 2 (Week 3)
3+
## Set of functions that caches the inversion of a matrix
54

5+
## makeCacheMatrix is function creates a special "matrix" object that can
6+
## cache its inverse.
67
makeCacheMatrix <- function(x = matrix()) {
7-
8+
## Return a vector that is a cache of an inverse matrix
9+
m <- NULL
10+
set <- function(y) {
11+
x <<- y
12+
m <<- NULL
13+
}
14+
get <- function() x
15+
setmatrix <- function(solve) m <<- solve
16+
getmatrix <- function() m
17+
list(set=set, get=get, setmatrix=setmatrix, getmatrix=getmatrix)
818
}
919

1020

11-
## Write a short comment describing this function
12-
21+
## This function computes the inverse of the special "matrix" returned by
22+
## makeCacheMatrix above. If the inverse has already been calculated (and the
23+
## matrix has not changed), then the cachesolve should retrieve the inverse
24+
## from the cache.
1325
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
26+
## Return a matrix that is the inverse of 'x'
27+
m <- x$getmatrix()
28+
if(!is.null(m)) {
29+
message("getting cached data")
30+
return(m)
31+
}
32+
data <- x$get()
33+
m <- solve(data, ...)
34+
x$setmatrix(m)
35+
m
1536
}

0 commit comments

Comments
 (0)