File tree Expand file tree Collapse file tree 1 file changed +20
-19
lines changed Expand file tree Collapse file tree 1 file changed +20
-19
lines changed Original file line number Diff line number Diff line change 33
44# # This function creates a special "matrix" object that can cache its inverse.
55
6- makeVector <- function (m = numeric ()) {
7- my <- NULL
8- set <- function (y ) {
9- x <<- y ;
10- m <<- NULL ;
6+ makeCacheMatrix <- function (my_x = matrix ()) {
7+ my_inv <- NULL
8+ set <- function (x ) {
9+ my_x <<- x ;
10+ my_inv <<- NULL ;
1111 }
12- get <- function () x ;
13- setmean <- function (mean ) my <<- mean ;
14- getmean <- function () m ;
15- list (set = set , get = get ,
16- setmean = setmean ,
17- getmean = getmean )
12+ get <- function () my_x ;
13+ setinv <- function (inv ) my_inv <<- inv ;
14+ getinv <- function () my_inv ;
15+ list (set = set ,
16+ get = get ,
17+ setinv = setinv ,
18+ getinv = getinv )
1819}
1920
2021# # This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
2122# # If the inverse has already been calculated (and the matrix has not changed), then the
2223# # cachesolve should retrieve the inverse from the cache.
2324
24- cachemean <- function (x , ... ) {
25- m <- x $ getinv()
26- if (! is.null(m )) {
27- message(" getting cached data" )
28- return ( m )
25+ cacheSolve <- function (x , ... ) {
26+ my_inv <- x $ getinv()
27+ if (! is.null(my_inv )) {
28+ message(" Looking up data from cache " )
29+ my_inv
2930 }
3031 data <- x $ get()
31- x <- mean (data , ... )
32- x $ setmean( m )
33- m
32+ my_inv <- solve (data , ... )
33+ x $ setinv( my_inv )
34+ my_inv
3435}
You can’t perform that action at this time.
0 commit comments