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

update cachematrix #3994

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

update cachematrix #3994

wants to merge 2 commits into from

Conversation

Amanfly
Copy link

@Amanfly Amanfly commented Apr 23, 2020

Write a short comment describing this function

#1. makeCacheMatrix: This function creates a special "matrix" object that can
#cache its inverse.

makeCacheMatrix <- function(x = matrix()) {

m1<- NULL
set <- function(y) {
    x <<- y
    m1 <<- NULL
}
get <- function() x
setinv <- function(solve) m1 <<- solve
getinv <- function() m1
list(set = set, get = get,
     setinv = setinv,
     getinv = getinv)

}

Write a short comment describing this function

#2. cacheSolve: This function computes the inverse of the special "matrix"
#returned by makeCacheMatrix above. If the inverse has already been calculated
#(and the matrix has not changed), then the cachesolve should retrieve the
#inverse from the cache.

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
}
m1<- x$getinv()
if(!is.null(m1)) {
message("getting cached data")
return(m1)
}
data <- x$get()
inv <- solve(data,diag(nrow(data)), ...)
x$setinv(m1)
m1
}

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