Skip to content

Commit 4412d02

Browse files
authored
Done
1 parent 7f657dd commit 4412d02

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cachematrix.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
31

4-
## Write a short comment describing this function
2+
#These functions compute and store in cache the inverse of a inversible matrix
3+
4+
## Cache a matrix inverse like in assigment text
55

66
makeCacheMatrix <- function(x = matrix()) {
7+
i <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
i <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inverse) i <<- inverse
14+
getinverse <- function() i
15+
list(set=set, get=get, setinverse=setinverse, getinverse=getinverse)
716

817
}
918

1019

11-
## Write a short comment describing this function
20+
## Solves a matrix inverse using cache if available like in assigment text
1221

1322
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
23+
i <- x$getinverse()
24+
if(!is.null(i)) {
25+
message("getting cached data.")
26+
return(i)
27+
}
28+
data <- x$get()
29+
i <- solve(data)
30+
x$setinverse(i)
31+
i
32+
1533
}

0 commit comments

Comments
 (0)