From 0b3d98f9e14c492492df3f86489ce2d70ab2625d Mon Sep 17 00:00:00 2001 From: prakashj Date: Wed, 23 Apr 2014 14:05:50 -0500 Subject: [PATCH 1/2] first check --- cachematrix.R | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..15942882ca5 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,35 @@ -## Put comments here that give an overall description of what your -## functions do +## -## Write a short comment describing this function +Put comments here that give an overall description of what your -makeCacheMatrix <- function(x = matrix()) { +## Make Cache Matrix same as Cache Mean.. +makeCacheMatrix <- function(x = matrix()) { + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setsolve <- function(solve) m <<- solve + getsolve <- function() m + list(set = set, get = get, + setsolve = setsolve, + getsolve = getsolve) } ## Write a short comment describing this function - +# cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + m <- x$getsolve() + if(!is.null(m)) { + message("getting cached data") + return(m) + } + data <- x$get() + m <- solve(data, ...) + x$setsolve(m) + m } From 837e685c3826a8e5ed4b320efac07eb2616c1fa7 Mon Sep 17 00:00:00 2001 From: prakashj Date: Wed, 23 Apr 2014 14:10:05 -0500 Subject: [PATCH 2/2] Updates --- cachematrix.R | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 15942882ca5..d7848d1defb 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,8 +1,4 @@ -## - -Put comments here that give an overall description of what your - -## Make Cache Matrix same as Cache Mean.. +## Make Cache Matrix function with various functions to cal inverse of matrix and cache makeCacheMatrix <- function(x = matrix()) { m <- NULL @@ -19,8 +15,8 @@ makeCacheMatrix <- function(x = matrix()) { } -## Write a short comment describing this function -# +## CacheSolve function .. checks whether the matrix solution exists. If yes, retrun cache else compute + cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' m <- x$getsolve()