Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion cachematrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@
## functions do

## Write a short comment describing this function
##The first function, `makeCacheMatrix` creates a special "Matrix", object that can cache its inverse.

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

makeCacheMatrix <- function(x = matrix()) {
inv<- NULL
set <- function(y){
x <<- y
inv <<- NULL
}

get<- function() x
setinv <- function(inverse) inv <<- inverse
getinv <- function() inv
list(set= set, get=get,
setinv = setinv,
getinv = getinv)
}


## Write a short comment describing this function
##This second function computes the inverse of the special "matrix" (obtained bu solve function) 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.

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