File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-6
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
1
+ # # Introduce `makeCacheMatrix` constructor function and `cacheSolve` function in
2
+ # # order to optimize getting of inverted matrix by caching already calculated results.
3
3
4
- # # Write a short comment describing this function
4
+ # # Constuctor function for matrix object
5
+ # # with stores inverted version of it.
5
6
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ inverted <- NULL ;
9
+ set <- function (y ) {
10
+ x <<- y
11
+ inverted <<- NULL
12
+ }
13
+ get <- function () x
14
+ setinverted <- function (invertedValud ) inverted <<- invertedValud
15
+ getinverted <- function () inverted
16
+ list (set = set , get = get ,
17
+ setinverted = setinverted ,
18
+ getinverted = getinverted )
8
19
}
9
20
10
21
11
- # # Write a short comment describing this function
22
+ # # Returns inverted matrix either from the cached version
23
+ # # or by explicitely calculating it with help of `solve` function.
24
+ # # x has to be `makeCacheMatrix` object.
12
25
13
26
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
27
+ inverted <- x $ getinverted()
28
+ if (! is.null(inverted )) {
29
+ message(" getting cached data" )
30
+ return (inverted )
31
+ }
32
+ data <- x $ get()
33
+ inverted <- solve(data , ... )
34
+ x $ setinverted(inverted )
35
+ inverted
15
36
}
You can’t perform that action at this time.
0 commit comments