From 37dbf0dadc9e43af3c0eb10e37728a7c7c28ad25 Mon Sep 17 00:00:00 2001 From: Fnu Divya Date: Mon, 21 Apr 2014 20:03:00 -0500 Subject: [PATCH] changes committed --- cachematrix.R | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..cb8efa870dd 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,30 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## This funciton uses solve() 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) } - - -## Write a short comment describing this function +## cacheSolve function check first if there matrix inverse is already calculated, else calculates using solve() function described above. cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + m <- x$getinverse() + if(!is.null(m)) { + message("display cached data") + return(m) + } + data <- x$get() + m <- solve(data, ...) + x$setinverse(m) + m + ## This method return a matrix that is the inverse of 'x' } +