forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
35 lines (31 loc) · 1.09 KB
/
cachematrix.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## This function caches the inverse of a matrix, and if the inverse has not already been calculated, it calculates it.
makeCacheMatrix <- function (x = matrix()){
m <- NULL
set <- function(y){
x <<- y
m <<- NULL
}
get <- function() x
setInverse <- function(inverse) m <<- inverse
getInverse <- function() m
## I expanded the names of the objects to make more sense to me
list(set = set, get = get,
setInverse = setInverse,
getInverse = getInverse)
## pretty much does the same thing the makeVector function except instead of
## taking the mean, it takes the inverse.
}
## Write a short comment describing this function
cacheSolve <- function(x, ...) {
m <- x$getInverse()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
## first it checks to see if m already exists. If it does, it returns cached data.
mat.data <- x$get()
m <- solve(mat.data, ...)
x$setInverse(m)
return(m)
##if m does not exist, it will "solve" the matrix to produce the inverse.
}