Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

## makeCacheMatrix function creates a "matrix" object that caches it… #2235

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

terrebonne
Copy link

…s inverse. #1. set value of the matrix #2. get value of the matrix #3. set value of the inverse #4. get value of the inversemakeCacheMatrix <- function(x = matrix()) { j <- NULL set <- function(y) { x <<- y j <<- NULL } get <- function() x setinverse <- function(solve) j <<- solve getinverse <- function() j list(set = set, get = get, setinverse = setinverse, getinverse = getinverse) } ## cacheSolve function computes the inverse of the "matrix" returned by makeCacheMatrix above. #If the inverse has already been calculated (and the matrix has not changed), thencacheSolve should retrieve the inverse from the cache. ## when giving: Error in x$getinverse : $ operator is invalid for atomic vectors cachesolve <- function(x, ...) { i<- x$getinverse() if(!is.null(j)) { message("getting cached data") return(j) } data <- x$get() j<- solve(data, ...) x$setinverse(j) j }

makeCacheMatrix function creates a "matrix" object that caches its inverse.

#1. set value of the matrix
#2. get value of the matrix
#3. set value of the inverse
#4. get value of the inversemakeCacheMatrix <- function(x = matrix()) {

j <- NULL
set <- function(y) {
  x <<- y
  j <<- NULL
}
get <- function() x
setinverse <- function(solve) j <<- solve
getinverse <- function() j
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)

}

cacheSolve function computes the inverse of the "matrix" returned by makeCacheMatrix above.

If the inverse has already been calculated (and the matrix has not changed), thencacheSolve should retrieve the inverse from the cache.

when giving: Error in x$getinverse : $ operator is invalid for atomic vectors

cachesolve <- function(x, ...) {
i<- x$getinverse()
if(!is.null(j)) {
message("getting cached data")
return(j)
}
data <- x$get()
j<- solve(data, ...)
x$setinverse(j)
j

}

…s inverse. #1.  set value of the matrix rdpeng#2.  get value of the matrix rdpeng#3.  set value of the inverse rdpeng#4.  get value of the inversemakeCacheMatrix <- function(x = matrix()) {      j <- NULL     set <- function(y) {       x <<- y       j <<- NULL     }     get <- function() x     setinverse <- function(solve) j <<- solve     getinverse <- function() j     list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)   } ## `cacheSolve` function computes the inverse of the "matrix" returned by `makeCacheMatrix` above.  #If the inverse has already been calculated (and the matrix has not changed), then`cacheSolve` should retrieve the inverse from the cache.  ## when giving: Error in x$getinverse : $ operator is invalid for atomic vectors cachesolve <- function(x, ...) {      i<- x$getinverse()     if(!is.null(j)) {       message("getting cached data")       return(j)     }     data <- x$get()     j<- solve(data, ...)     x$setinverse(j)     j  }


## makeCacheMatrix function creates a "matrix" object that caches its inverse.
#1.  set value of the matrix
rdpeng#2.  get value of the matrix
rdpeng#3.  set value of the inverse
rdpeng#4.  get value of the inversemakeCacheMatrix <- function(x = matrix()) {

    j <- NULL
    set <- function(y) {
      x <<- y
      j <<- NULL
    }
    get <- function() x
    setinverse <- function(solve) j <<- solve
    getinverse <- function() j
    list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
 
}
## `cacheSolve` function computes the inverse of the "matrix" returned by `makeCacheMatrix` above. 
#If the inverse has already been calculated (and the matrix has not changed), then`cacheSolve` should retrieve the inverse from the cache.

## when giving: Error in x$getinverse : $ operator is invalid for atomic vectors
cachesolve <- function(x, ...) { 
    i<- x$getinverse()
    if(!is.null(j)) {
      message("getting cached data")
      return(j)
    }
    data <- x$get()
    j<- solve(data, ...)
    x$setinverse(j)
    j

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant