Skip to content

Commit

Permalink
Adding implementaion for makeCacheMatrix and cacheSolve
Browse files Browse the repository at this point in the history
  • Loading branch information
prasar-ashutosh committed Jan 29, 2017
1 parent 7f657dd commit d6ee3f5
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
## Put comments here that give an overall description of what your
## functions do
## Below functions compute inverse of a matrix and cache the result
## As per the assignment, the matrix supplied must be invertible

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

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

}


## Write a short comment describing this function
## 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'
inv <- x$getInverse()
if(!is.null(inv)) {
message("getting cached data")
return(inv)
}
data <- x$get()
inv <- solve(data,...)
x$setInverse(inv)
inv
}

0 comments on commit d6ee3f5

Please sign in to comment.