Skip to content

Commit 1a3a49e

Browse files
committed
Update cachematrix.R
1 parent 7f657dd commit 1a3a49e

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

cachematrix.R

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
1+
## makeCacheMatrix is the fuctintion creating an object and calculated the inversion value of the matrix.
2+
## In case there is the matrix already calculated the cached value is used instead of calculation
63
makeCacheMatrix <- function(x = matrix()) {
7-
4+
invValX <- NULL
5+
set <- function(Y)
6+
{
7+
x <<- y
8+
invValX <<- NULL
9+
}
10+
11+
get <- function() x
12+
13+
setinverse<- function(inverse) inv_x <<-inverse
14+
getinverse <- function() inv_x
15+
list(set = set, get = get,
16+
setinverse = setinverse,
17+
getinverse = getinverse)
818
}
919

10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
20+
## The function cacheSolve returns the inverse of a matrix by function makeCacheMatrix.
21+
## If the object is not stored in cached it is created and set to cached and retuned to calling context.
22+
cacheSolve <- function(x, ...)
23+
{
24+
## Get the inverse value of 'x'
25+
invValX <- x$getinverse()
26+
if (!is.null(invValX))
27+
{
28+
message("The cached value is returned.")
29+
return(invValX)
30+
} else {
31+
invValX <- solve(x$get())
32+
x$setinverse(invValX)
33+
}
34+
35+
return(invValX)
1536
}

0 commit comments

Comments
 (0)