forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammingAssignment2.R
More file actions
28 lines (28 loc) · 1006 Bytes
/
ProgrammingAssignment2.R
File metadata and controls
28 lines (28 loc) · 1006 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
makeCacheMatrix <- function(x = matrix()){
# makeCacheMatrix will create a list containing a function
# to set, get the value of a matrix, and
# set, get the value of the inverse of a matrix
matrix.inverse <- NULL
set <- function(y){
x <<- y
matrix.inverse <<- NULL
}
get <- function() x
setinv <- function(inv) matrix.inverse <<- inv
getinv <- function() matrix.inverse
list(set = set, get = get, setinv = setinv, getinv = getinv)
}
cacheSolve <- function(x, ...){
# calculates the inverse of a matrix
# returns a matrix inverse
# if the matrix inverse is not null
matrix.inverse <- x$getinv()
if(!is.null(matrix.inverse)){
message("getting cached data")
return(matrix.inverse)
}
data <- x$get()
matrix.inverse <- solve(data, ...)
x$setinv(matrix.inverse)
return(matrix.inverse)
}