Skip to content

Commit bee81fc

Browse files
committed
Update cachematrix.R
1 parent 0e0c0f3 commit bee81fc

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

cachematrix.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,45 @@
22
## In case there is the matrix already calculated the cached value is used instead of calculation
33
makeCacheMatrix <- function(x = matrix()) {
44

5-
## Initialization
5+
# Initialization of cache to null
66
invValX <- NULL
77

8+
# Store matrix
89
set <- function(Y)
910
{
1011
x <<- y
1112
invValX <<- NULL
1213
}
1314

15+
# Get matrix
1416
get <- function() x
1517

1618
# Calculate the inverse value
1719
setinverse<- function(inverse) invValX <<-inverse
1820
getinverse <- function() invValX
1921

22+
# Return a list object
2023
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
2124
}
2225

2326
## The function cacheSolve returns the inverse of a matrix by function makeCacheMatrix.
2427
## If the object is not stored in cached it is created and set to cached and retuned to calling context.
2528
cacheSolve <- function(x, ...)
2629
{
27-
## Get the inverse value of 'x' if any
30+
# Get the inverse value of 'x' if any
2831
invValX <- x$getinverse()
2932

30-
## is there any object in cache?
33+
# is there any object in cache?
3134
if (!is.null(invValX))
3235
{
33-
message("The cached value is returned.")
36+
message("The cached inverse value is returned.")
3437
return(invValX)
3538
}
3639

37-
## Cache is empty, calculate the value and store it in cache
40+
# Cache is empty, calculate the value and store it in cache
41+
message("Calculating a new inverse value and storing it in cache.")
3842
invValX <- solve(x$get())
39-
#set the object into cache
43+
# Set the object into cache
4044
x$setinverse(invValX)
4145

4246
return(invValX)

0 commit comments

Comments
 (0)