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
44 lines (40 loc) · 1.11 KB
/
Copy pathcachematrix.R
File metadata and controls
44 lines (40 loc) · 1.11 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
42
43
44
## Put comments here that give an overall description of what your
## functions do
## The makeCacheMatrix function cache the matrix
makeCacheMatrix <- function(x = matrix()) {
# Clear the inverse veriable
inverse <- NULL
# Store the matrix in veriable y and clear the stored inverse
# veriablewhen a new matrix was setted
set <-function(y){
x<<-y
inverse<<-NULL
}
# Return the stored matrix
get <- function(){
x
}
# Set the inverse matrix
setinverse <- function(inv){
inverse <<-inv
}
# Get the inverse matrix
getinverse <- function() {
inverse
}
list(set = set, get=get ,setinverse = setinverse, getinverse=getinverse)
}
## Return the matrix if there is on in the cache
## Otherwise, compute the inverse of the matrix
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inverse <- x$getinverse()
if(!is.null(inverse)) {
message("getting cached data")
return(inverse)
}
data <- x$get()
inverse <- solve(data, ...)
x$setinverse(inverse)
inverse
}