forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
42 lines (37 loc) · 1.06 KB
/
cachematrix.R
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
## Cached inverse functions
## author: Victor hugo bustamante
## date: may 17, 2014
## Storing a matrix and its inverse.
## Define: functions get for obtain the matrix,
## set to store the matrix,
## getinv for obtain inverse and
## setinv to store the inverse
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
set <- function(y) {
x <<- y
## initialize inverse to NULL
m <<- NULL
}
get <- function() x
setinv <- function(inverse) m <<- inverse
getinv <- function() m
## return list
list( set=set, get=get,
setinv=setinv,
getinv=getinv)
}
## computes the inverse of the matrix where it has not been calculated
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getinv()
if (!is.null(m)) {
## return cached inverse
return(m)
}
data <- x$get()
m <- solve(data)
x$setinv(m)
## inverse calculated
m
}