File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Expand file tree Collapse file tree 1 file changed +24
-8
lines changed 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
3
-
4
- # # Write a short comment describing this function
1
+ # # The matrix inversion is usualy a costly operation.
2
+ # # The set of functions below intended to cache matrix inverse
3
+ # # to save computational time on inverse calculartion.
5
4
5
+ # # This function creates a special "matrix" object that can cache its inverse.
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ i <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ i <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinv <- function (inverse ) i <<- inverse
14
+ getinv <- function () i
15
+ list (set = set , get = get , setinv = setinv , getinv = getinv )
8
16
}
9
17
10
18
11
- # # Write a short comment describing this function
12
-
19
+ # # This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
20
+ # # If the inverse has already been calculated, then the cachesolve should retrieve the inverse from the cache
13
21
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
22
+ # # Return a matrix that is the inverse of 'x'
23
+ i <- x $ getinv()
24
+ if (! is.null(i )) {
25
+ return (i )
26
+ }
27
+ data <- x $ get()
28
+ inverse <- solve(data , ... )
29
+ x $ setinv(inverse )
30
+ inverse
15
31
}
You can’t perform that action at this time.
0 commit comments