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
48 lines (45 loc) · 1.35 KB
/
cachematrix.R
File metadata and controls
48 lines (45 loc) · 1.35 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
43
44
45
46
47
48
## Put comments here that give an overall description of what your
## functions doc
## This set of functions manages the calculation of the inverse of a matrix.
## If the matrix being passed in has already had its inverse calculated, the
## Methods will return the cached inverse of the matrix. If the inverse matrix
## is not in the cache, the functions will compute the inverse of the matrix
## and cache the inverted matrix
## Write a short comment describing this function
## This function manages the cache and functions for setting and getting
## items from the cache.
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
set <- function(y) {
x <<- y
m <<- NULL
}
get <- function() {
x
}
setSolve <- function(solve) {
m <<- solve
}
getSolve <- function() {
m
}
list(set = set, get = get,
setSolve = setSolve,
getSolve = getSolve)
}
## Write a short comment describing this function
## This function calculates the inverse of a matrix. It uses the makeCacheMatrix
## function to cache the results and uses the cached value if the matrix is
## passed in again.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getSolve()
if(!is.null(m)) {
message("Getting cached inverse of matrix")
return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setSolve(m)
m
}