File tree Expand file tree Collapse file tree 1 file changed +35
-8
lines changed Expand file tree Collapse file tree 1 file changed +35
-8
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
1
+ # # Functions for cache result of matrix inversion.
2
+ # #
3
+ # # Example:
4
+ # # > x <- makeCacheMatrix(matrix(1:4, nrow = 2, ncol=2))
5
+ # # > cacheSolve(x)
6
+ # # [,1] [,2]
7
+ # # [1,] -2 1.5
8
+ # # [2,] 1 -0.5
9
+ # # > cacheSolve(x)
10
+ # # getting cached data
11
+ # # [,1] [,2]
12
+ # # [1,] -2 1.5
13
+ # # [2,] 1 -0.5
5
14
15
+ # # Make special cachable version of matrix
6
16
makeCacheMatrix <- function (x = matrix ()) {
7
-
17
+ c <- NULL
18
+ set <- function (y ) {
19
+ x <<- y
20
+ c <<- NULL
21
+ }
22
+ get <- function () x
23
+ setsolve <- function (solved ) c <<- solved
24
+ getsolve <- function () c
25
+ list (set = set , get = get ,
26
+ setsolve = setsolve ,
27
+ getsolve = getsolve )
8
28
}
9
29
10
30
11
- # # Write a short comment describing this function
12
-
31
+ # # Solve matrix or get cached result if already solved
13
32
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
33
+ m <- x $ getsolve()
34
+ if (! is.null(m )) {
35
+ message(" getting cached data" )
36
+ return (m )
37
+ }
38
+ data <- x $ get()
39
+ m <- solve(data , ... )
40
+ x $ setsolve(m )
41
+ m
15
42
}
You can’t perform that action at this time.
0 commit comments