File tree Expand file tree Collapse file tree 1 file changed +32
-5
lines changed Expand file tree Collapse file tree 1 file changed +32
-5
lines changed Original file line number Diff line number Diff line change 1
1
# # Put comments here that give an overall description of what your
2
2
# # functions do
3
3
4
- # # Write a short comment describing this function
4
+ # # Takes matrix and returns special matrix which is list containing functions:
5
+ # # get() - returns initial matrix
6
+ # # set(y) - overwrites initial matrix with new one
7
+ # # getsolved() - returns cached inverse of initial matrix
8
+ # # setsolved() - caches inverse of matrix
5
9
6
10
makeCacheMatrix <- function (x = matrix ()) {
7
-
11
+ s <- NULL
12
+
13
+ get <- function () x
14
+ set <- function (y ) {
15
+ x <<- y
16
+ s <<- NULL
17
+ }
18
+
19
+ getsolved <- function () s
20
+ setsolved <- function (solved ) s <<- solved
21
+
22
+ list (get = get ,
23
+ set = set ,
24
+ getsolved = getsolved ,
25
+ setsolved = setsolved )
8
26
}
9
27
10
-
11
- # # Write a short comment describing this function
28
+ # # Takes special matrix and checks if it has cached inverse of matrix.
29
+ # # If not it computes inverse of matrix and stores it in cache.
30
+ # # It returns inverse of matrix as a result
12
31
13
32
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
33
+ solved <- x $ getsolved()
34
+
35
+ if (is.null(solved )) {
36
+ matrix <- x $ get()
37
+ solved <- solve(matrix , ... )
38
+ x $ setsolved(solved )
39
+ }
40
+
41
+ solved
15
42
}
You can’t perform that action at this time.
0 commit comments