From 1ca9f9155550d74c4c6b61ecca66e1a8e88dd82f Mon Sep 17 00:00:00 2001 From: Xerik Date: Wed, 8 Jun 2016 23:46:42 -0400 Subject: [PATCH 1/2] Modified file as per assignment requirements --- cachematrix.R | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..4f33eb9eca4 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 +## This function takes a matrix and has functions to cache and return the transpose of that matrix makeCacheMatrix <- function(x = matrix()) { - + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setTranspose <- function(t) m <<- t + getTranspose <- function() m + list(set = set, get = get, + setTranspose = setTranspose, + getTranspose = getTranspose) } -## Write a short comment describing this function +## This will check to see if there is a stored transpose matrix, it not, then it will take the transpose of the matrix +## and assign the transpose to m cacheSolve <- function(x, ...) { + m <- x$getTranspose() + if(!is.null(m)) { + message("getting cached data") + return(m) + } + data <- x$get() + m <- t(data) + x$setTranspose(m) + m ## Return a matrix that is the inverse of 'x' } From 3683c6e640363449efcc4ace7217bb28f12d4f19 Mon Sep 17 00:00:00 2001 From: Xerik Date: Thu, 9 Jun 2016 00:36:30 -0400 Subject: [PATCH 2/2] Misread problem statmeent I thought we should take the transpose of the matrix. It is actually the inverse of the matrix. I've updated the code to reflect that. --- cachematrix.R | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 4f33eb9eca4..d860ab777de 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,7 +1,7 @@ ## Put comments here that give an overall description of what your ## functions do -## This function takes a matrix and has functions to cache and return the transpose of that matrix +## This function takes a matrix and has functions to cache and return the inverse of that matrix makeCacheMatrix <- function(x = matrix()) { m <- NULL @@ -10,26 +10,26 @@ makeCacheMatrix <- function(x = matrix()) { m <<- NULL } get <- function() x - setTranspose <- function(t) m <<- t - getTranspose <- function() m + setInverse <- function(solve) m <<- solve + getInverse <- function() m list(set = set, get = get, - setTranspose = setTranspose, - getTranspose = getTranspose) + setInverse = setInverse, + getInverse = getInverse) } -## This will check to see if there is a stored transpose matrix, it not, then it will take the transpose of the matrix -## and assign the transpose to m +## This will check to see if there is a stored Inverse matrix, it not, then it will take the transpose of the matrix +## and assign the Inverse to m cacheSolve <- function(x, ...) { - m <- x$getTranspose() + m <- x$getInverse() if(!is.null(m)) { message("getting cached data") return(m) } data <- x$get() - m <- t(data) - x$setTranspose(m) + m <- solve(data) + x$setInverse(m) m - ## Return a matrix that is the inverse of 'x' + ## Return a matrix that is the inverse of 'x' }