File tree Expand file tree Collapse file tree 1 file changed +27
-7
lines changed Expand file tree Collapse file tree 1 file changed +27
-7
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
+ # # Use example:
2
+ # # a <- makeCacheMatrix(matrix(1:4,2,2))
3
+ # # cacheSolve(a) # real computations
4
+ # # cacheSolve(a) # extracting from cache
5
5
6
+ # # Make a special cache object, vary much like a class.
7
+ # # Same as original assignment
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ m <- NULL
10
+ set <- function (y ) {
11
+ x <<- y
12
+ m <<- NULL
13
+ }
14
+ get <- function () x
15
+ setinv <- function (inv ) m <<- inv
16
+ getinv <- function () m
17
+ list (set = set , get = get ,
18
+ setinv = setinv ,
19
+ getinv = getinv )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # Same function as original, just use solve instead mean
12
24
13
25
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
26
+ m <- x $ getinv()
27
+ if (! is.null(m )) {
28
+ message(" getting cached data" )
29
+ return (m )
30
+ }
31
+ data <- x $ get()
32
+ m <- solve(data , ... )
33
+ x $ setinv(m )
34
+ m
15
35
}
You can’t perform that action at this time.
0 commit comments