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
31 lines (26 loc) · 828 Bytes
/
cachematrix.R
File metadata and controls
31 lines (26 loc) · 828 Bytes
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
## Put comments here that give an overall description of what your
## functions do
## This function caches or stores the matrix and its inverse.
makeCacheMatrix <- function(x = matrix()) {
cache <- NULL
setmatrix <- function(newvalue){
x<<- newvalue
cache <<- NULL
}
getmatrix <- function() x
cacheInverse <- function() cache
list(setmatrix= setmatrix, getmatrix= getmatrix, cacheInverse= cacheInverse, getInverse= getInverse)
}
## This function solves for the inverse of the matrix.
cacheSolve <- function(x, ...) {
inverse <- x$getinverse()
if(! is.null(inverse)){
message("getting inverse")
return(inverse)
}
data <- x$getMatrix()
inverse <- solve(data,...)
x$cacheInverse(inverse)
inverse
## Return a matrix that is the inverse of 'x'
}