File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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+ # # These function are used to make a matrix object that can cache its inverse
2+ # # and return the cached inverse of that matrix
33
4- # # Write a short comment describing this function
4+ # # makeCacheMatrix makes a special matrix object that can cache its inverse
55
66makeCacheMatrix <- function (x = matrix ()) {
7-
7+ m <- NULL
8+ set <- function (y ) {
9+ x <<- y
10+ m <<- NULL
11+ }
12+ get <- function () x
13+ setInv <- function (solve ) m <<- solve
14+ getInv <- function () m
15+ list (set = set , get = get ,
16+ setInv = setInv ,
17+ getInv = getInv )
818}
919
1020
11- # # Write a short comment describing this function
21+ # # cacheSolve then computes the inverse of the special matrix returnet by the
22+ # # function makeCacheMatrix.
23+ # # If the inverse has alredy been calculated and the matrix is the same
24+ # # then cacheSolve should retrieve the inverse from the cache
1225
1326cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
27+ m <- x $ getInv()
28+ if (! is.null(m )) {
29+ message(" getting cached data" )
30+ return (m )
31+ }
32+ data <- x $ get()
33+ m <- solve(data , ... )
34+ x $ setInv(m )
35+ m
1536}
You can’t perform that action at this time.
0 commit comments