From 137d515604399d6c1a80e15737e59deb4406c342 Mon Sep 17 00:00:00 2001 From: Sean Ferenci Date: Sun, 20 Apr 2014 11:55:20 -0400 Subject: [PATCH 1/2] Assignment Complete --- cachematrix.R | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..b2bb2c8c8aa 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,7 +4,17 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + i <- NULL + set <- function(y) { + x <<- y + i <<- NULL + } + get <- function() x + setinverse <- function(solved) i <<- solved + getinverse <- function() i + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) } @@ -12,4 +22,13 @@ makeCacheMatrix <- function(x = matrix()) { cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + i <- x$getinverse() + if(!is.null(i)) { + message("getting cached data") + return(i) + } + data <- x$get() + i <- solve(data, ...) + x$setinverse(i) + i } From 1c8925bf88c249c4cee5fd705005592df704a672 Mon Sep 17 00:00:00 2001 From: Sean Ferenci Date: Sun, 20 Apr 2014 12:02:58 -0400 Subject: [PATCH 2/2] Added comments --- cachematrix.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index b2bb2c8c8aa..c356975ef7d 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,7 +1,11 @@ -## Put comments here that give an overall description of what your -## functions do +## Written by Sean Ferenci, P.Eng. +## April 20, 2014 -## Write a short comment describing this function +## makeCacheMatrix creates a special "Matrix", which is really a list containing a function to +## set the value of the matrix +## get the value of the matrix +## set the value of the inverse matrix +## get the value of the inverse matrix makeCacheMatrix <- function(x = matrix()) { i <- NULL @@ -18,7 +22,9 @@ makeCacheMatrix <- function(x = matrix()) { } -## 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'