File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
1+ # # This code uses caching to avoid recalculating inverse matrices.
32
4- # # Write a short comment describing this function
53
6- makeCacheMatrix <- function ( x = matrix ()) {
4+ # # Function below allows to create a matrix that can then store its inverse in cache.
75
6+ 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 ,
16+ setinverse = setinverse ,
17+ getinverse = getinverse )
818}
919
1020
11- # # Write a short comment describing this function
21+ # # Function below allows to get the cached inverse matrix of the object created by makeCacheMatrix
22+ # # or calculate the inverse matrix if necessary.
1223
1324cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
25+ i <- x $ getinverse()
26+ if (! is.null(i )) {
27+ message(" getting cached data" )
28+ return (i )
29+ }
30+ data <- x $ get()
31+ i <- solve(data , ... )
32+ x $ setinverse(i )
33+ i
1534}
You can’t perform that action at this time.
0 commit comments