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
41 lines (36 loc) · 1.06 KB
/
cachematrix.R
File metadata and controls
41 lines (36 loc) · 1.06 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
## A pair of functions to facilitate the cacheing of a matrix and its inverse
## Creates an object to store, set, and get the matrix and inverse
## matrix of a given input matrix
## Function Description:
## get() - Returns the current matrix
## set() - Sets the current matiix
## get.inverse() - Retuns the inverse matrix
## set.inverse() - Sets the inverse matrix
makeCacheMatrix <- function(x = matrix()) {
m <- x
im <- NULL
set <- function(y) {
m <<- y
im <<- NULL
}
get <- function() m
set.inverse <- function(inverse.matrix) im <<- inverse.matrix
get.inverse <- function() im
list(set = set, get = get,
set.inverse = set.inverse,
get.inverse = get.inverse)
}
## Solves for the inverse matrix for a makeCacheMatrix object, or returns
## the current inverse matrix if it's already solved
cacheSolve <- function(x, ...) {
im <- x$get.inverse()
if(!is.null(im)) {
message("getting cached data")
return(im)
}
m <- x$get()
im <- solve(m)
x$set.inverse(im)
im
## Return a matrix that is the inverse of 'x'
}