1
1
# # Functions for cached matrix inverse operation
2
2
3
+ # # makeCacheMatrix is used for creation of special
4
+ # # matrix object that caches the calculated inverse
5
+ # # until the matrix itself changes.
6
+ # # cacheSolve uses special matrix object x created by
7
+ # # makeCachedMatrix in order to calculate the inverse
8
+ # # of the matrix x. When the matrix inversion result
9
+ # # from previous calculation is available in the cache,
10
+ # # it is just reported back without the new recalculation.
11
+ # # Otherwise, the inverse is calculated and stored in
12
+ # # the cache for future reuse
13
+
3
14
4
15
# # makeCacheMatrix creates special form of matrix that
5
16
# # enables caching of matrix inverse calculations
6
17
7
18
makeCacheMatrix <- function (x = matrix ()) {
8
19
inv <- NULL
9
20
set <- function (y ) {
10
- x <<- y
11
- inv <<- NULL
21
+ if (! identical(x ,y ))
22
+ {
23
+ x <<- y
24
+ inv <<- NULL
25
+ }
12
26
}
13
27
get <- function () x
14
28
setinv <- function (inverse ) inv <<- inverse
@@ -19,12 +33,9 @@ makeCacheMatrix <- function(x = matrix()) {
19
33
}
20
34
21
35
22
- # # cacheSolve uses special matrix object x created by makeCachedMatrix
23
- # # in order to calculate the inverse of the matrix x.
24
- # # When the matrix inversion result from previous calculation
25
- # # is available in the cache, it is just reported back
26
- # # without the new recalculation. Otherwise, the inverse is
27
- # # calculated and stored in the cache for future reuse
36
+ # # cacheSolve takes special form of matrix as input
37
+ # # and returns its inverse, either by reporting the cached
38
+ # # or calculated version
28
39
29
40
cacheSolve <- function (x , ... ) {
30
41
# # Return a matrix that is the inverse of 'x'
0 commit comments