forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
42 lines (37 loc) · 1.12 KB
/
Copy pathcachematrix.R
File metadata and controls
42 lines (37 loc) · 1.12 KB
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
35
36
37
38
39
40
41
42
## Put comments here that give an overall description of what your
## functions do
## Create the cache for the matrix; assign output to variable to use in cacheSolve
## Ex. mat<-makeCacheMatric(your_matrix)
makeCacheMatrix <- function(x = matrix()) {
#set the value of the matrix
m <- NULL
set <- function(y) {
x <<- y
m <<- NULL
}
#get the value of the matrix
get <- function() x
#set the value of the inverse
setsolve <- function(solve) m <<- solve
#get the value of the inverse
getsolve <- function() m
list(set = set, get = get,
setsolve = setsolve,
getsolve = getsolve)
}
## Solve for inverse of matrix and stores result in cache; will return 'getting cached data' on second run
## Ex. cacheSolve(mat)
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getsolve()
#message prompt if inverse matrix exists in cache
if(!is.null(m)) {
message("getting cached data")
return(m)
}
#runs function if inverse matrix is not found in cache
data <- x$get()
m <- solve(data, ...)
x$setsolve(m)
m
}