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
34 lines (30 loc) · 1.07 KB
/
cachematrix.R
File metadata and controls
34 lines (30 loc) · 1.07 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
## These tow functions works tougether to compute an inverse matrix and cache the resolte
## functions do
## This function creates a set of functions that get a matrix and it´s inverse.
#Once inverse matrix is computed, the function caches the result.
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
set.matrix <- function(y) {
x <<- y
m <<- NULL
}
get.matrix <- function() x
set.inverse <- function(inverse) m <<- inverse
get.inverse <- function() m
list(set.matrix = set.matrix, get.matrix = get.matrix,
set.inverse = set.inverse,
get.inverse = get.inverse)
}
## This function computes the inverse of a matrix, since it was not been calculated and stored on cache by the function above.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$get.inverse()
if(!is.null(m)) {
message("getting cached inverse matrix")
return(m)
}
data <- x$get.matrix()
m <- solve(data)
x$set.inverse(m)
m
}