Skip to content

Commit

Permalink
Update cachematrix.R
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantmonu51 committed Apr 27, 2014
1 parent 7f657dd commit c9a6e79
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
## Put comments here that give an overall description of what your
## functions do

## Write a short comment describing this function
## Creates a special "matrix" object that can cache its inverse.

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

inverse <- NULL
## modify the reference of matrix
set <- function(newReference){
x <<- newReference
inverse <<- NULL
}
## get the matrix
get <- function() x
## cache the inverse
setinverse <- function(inverse) inverse <<- inverse
## get the cached inverse
getinverse <- function() inverse
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'
## Computes the inverse. If the inverse has been cached returns the cached value
cacheSolve<- function(x, ...) {
i <- x$getinverse()
## If matrix is cached already return cached data
if (!is.null(i)){
message("getting cached data")
return(i)
}
## calculate the inverse
data <- x$get()
i <- solve(data, ...)
## cache inverse
x$setinverse(i)
i
}

0 comments on commit c9a6e79

Please sign in to comment.