From 7a28ce2b9b7145734d7c97722191d425bdba57d5 Mon Sep 17 00:00:00 2001 From: YanasR Date: Wed, 20 May 2015 22:37:33 +0530 Subject: [PATCH] completed the function to inverse completed the function cache and get inverse of a matrix --- cachematrix.R | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa4..2b96991fbc 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,10 +1,24 @@ -## Put comments here that give an overall description of what your -## functions do +## This function does the following things +## 1) set the value of the matrix +## 2) get the value of the matrix +## 3) set the value of the inverse +## 4) get the value of the inverse ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setinverse <- function(solve) m <<- solve + getinverse <- function() m + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) } @@ -12,4 +26,20 @@ makeCacheMatrix <- function(x = matrix()) { cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + + m <- x$getinverse() + if(!is.null(m)) { + message("getting cached data") + return(m) + } + data <- x$get() + m <- solve(data, ...) + x$setinverse(m) + m } + + + + + +