File tree Expand file tree Collapse file tree 1 file changed +32
-11
lines changed Expand file tree Collapse file tree 1 file changed +32
-11
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
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
6
3
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 )
8
18
}
9
19
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 )
15
36
}
You can’t perform that action at this time.
0 commit comments