0

I am a beginner in R and I was doing a programming assignment from Coursera. The question involves caching of Inverse of matrix in R. I know it has been been asked many times but I am still not able to understand those solutions. Can someone dry run it from step 1 with an input and explain each and every step for better understanding? It would be highly appreciated.Basically I am more confused with the set functions and it's parameters. what would be value of y?

makeCacheMatrix <- function(x = matrix()) {
  j <- NULL
  set <- function(y){
    x <<- y
    j <<- NULL
  }
  get <- function()x
  setInverse <- function(inverse) j <<- inverse
  getInverse <- function() j 
  list(set = set, get = get, 
       setInverse = setInverse, 
       getInverse = getInverse)

}


## Write a short comment describing this function

cacheSolve <- function(x, ...) {
        ## Return a matrix that is the inverse of 'x'
  j <- x$getInverse()
  if(!is.null(j)){
    message("getting cached data")
    return(j)
  }
  mat <- x$get()
  j <- solve(mat,...)
  x$setInverse(j)
  j
}
  • Hello Kunal. Welcome to StackOverflow. Since your question is part of a Johns Hopkins University homework assignment, we can't give you a walkthrough of this code without violating the Coursera Honor Code. However, the URL in the previous comment references my walkthrough of the sample program for this assignment, `makeVector()` and `cachemean()`. It's a line by line walkthrough covers how the `set()` function works. – Len Greski Apr 08 '20 at 23:01
  • 1
    @LenGreski Wow, this really is a duplicate. – Ian Campbell Apr 08 '20 at 23:38
  • Or more generally [cache mean of vector](https://stackoverflow.com/questions/24904683/caching-the-mean-of-a-vector-in-r/47723281#47723281) also by @LenGreski. Interesting read. – Chris Apr 09 '20 at 06:29

0 Answers0