Skip to content

Commit ef0b9b0

Browse files
author
entmoot
committed
improvements
1 parent a66c854 commit ef0b9b0

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

cachematrix.R

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
## Functions for cached matrix inverse operation
22

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+
314

415
## makeCacheMatrix creates special form of matrix that
516
## enables caching of matrix inverse calculations
617

718
makeCacheMatrix <- function(x = matrix()) {
819
inv<-NULL
920
set <- function(y) {
10-
x <<- y
11-
inv <<- NULL
21+
if (!identical(x,y))
22+
{
23+
x <<- y
24+
inv <<- NULL
25+
}
1226
}
1327
get <- function() x
1428
setinv <- function(inverse) inv <<- inverse
@@ -19,12 +33,9 @@ makeCacheMatrix <- function(x = matrix()) {
1933
}
2034

2135

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
2839

2940
cacheSolve <- function(x, ...) {
3041
## Return a matrix that is the inverse of 'x'

0 commit comments

Comments
 (0)