From 8bcf0adc91df5f1c3d121194b159085dbc788644 Mon Sep 17 00:00:00 2001 From: themby528 Date: Mon, 21 Apr 2014 15:39:27 -0400 Subject: [PATCH] First edits of ProgrammingAssignment 2 (Peer Eval) --- .cachematrix.R.swp | Bin 0 -> 12288 bytes cachematrix.R | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 .cachematrix.R.swp diff --git a/.cachematrix.R.swp b/.cachematrix.R.swp new file mode 100644 index 0000000000000000000000000000000000000000..999691e2ba86f977283e6dc5fb5bea32c4920a8f GIT binary patch literal 12288 zcmeI&K~EDw6bJB!9{`O+&rf>*65SRWLNt1)LIQ>wQc_I3E!&};*xkjMSu7a7iyr_E zCdQNcsl4ld+G66RAs#$5|4IJcHr;vq=67u0QR8s8t(!?xukX>X4xsTjKeq!$rrP3Q&Lo6rjL=6fi!M z_mvHDF@6oA(^ac!$Aroin(Ab7T*Dv@YCWz-ZE=dRbED<4E{~RFJYarM4o{6fd#uM* zkp){8E2Br6B+06N6hXZ=&IW^Weo(rgS((S-bnT%9XOA$kj>4#Zy%`7>B6<4Gyo}T9 z?eX;b-_`Z`w6&Ghe|-kpx_+S7UK!imul_XWbzq#C9K3IFxU|p`2TzB?Y2PRDoKfLJ K#5pS~C%*y1BAnp> literal 0 HcmV?d00001 diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..64f8ca4b84f 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,46 @@ -## Put comments here that give an overall description of what your -## functions do +## The functions below will take an input such as matrix(c(1,2,3,4),2,2) and return the inverse of this matrix. +## They will first check if the inverse is already in the cache and if so return that cache value, if not the matric +## inverse will be solve for and returned -## Write a short comment describing this function -makeCacheMatrix <- function(x = matrix()) { +## This function will take the user input and create matrix of the values that is store in the cache +makeCacheMatrix <- function(x = matrix()) { + ## create m vector + m <- NULL + ## create the values provided as a matrix + set <- function(y) { + x <<- y + m <<- NULL + } + ## return the matrix of the inputs supplied + get <- function() x + ## stores the function solve for use when pulling data from cache + setinverse <- function(solve) m <<- solve + ## this will print the inverse when called + getinverse <- function() m + ## create a list that holds the names of the items you just stored in the cache + list(set = set, get = get, setinverse = setinverse, getinverse = getinverse) + } -## Write a short comment describing this function +## This function will check the cache for the inverse of the defined matrix +## If found it will return the inverse from cache and if not it will create the inverse and store it for later cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## check if the inverse of the amtrix already exists in the cache + m <- x$getinverse() + ## if m is not empty (meaning there is something in the cache for inverse of X), pull the value from cache + if(!is.null(m)) { + message("getting cached data") + return(m) + } + ## get the x matrix from the cache and store it in the data variable + data <- x$get() + ## run the solve function from the cache with the solve function + m <- solve(data, ...) + ## store the inverse + x$setinverse(m) + m }