File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Expand file tree Collapse file tree 1 file changed +24
-6
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
1
+ # # Functions for computing inverse matrix for given matrix, caching
2
+ # # the result for future use within the program
3
3
4
- # # Write a short comment describing this function
4
+ # # Special type of matrix, which can save also its inverse matrix
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ im <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ im <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (inverse ) im <<- inverse
14
+ getinverse <- function () im
15
+ list (set = set , get = get ,
16
+ setinverse = setinverse ,
17
+ getinverse = getinverse )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
21
+ # # Function for computing inverse matrix, caching the result within CacheMatrix
12
22
13
23
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
24
+ im <- x $ getinverse()
25
+ if (! is.null(im )) {
26
+ message(" getting cached data" )
27
+ return (im )
28
+ }
29
+ data <- x $ get()
30
+ im <- solve(data , ... )
31
+ x $ setinverse(im )
32
+ im
15
33
}
You can’t perform that action at this time.
0 commit comments