From 1eacc53907ff612bcc7dfd813f4118a7d6b4abed Mon Sep 17 00:00:00 2001 From: Datum 2020 Date: Sun, 24 Aug 2014 16:29:49 -0700 Subject: [PATCH] Update README as specified solve --- cachematrix.R | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..e11c0158089 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,38 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## This routine takes as input a matrix from the user +## and creates a special object that can optimize matrix +## inversion by caching results. +## Example: sqmar +## sqmat <- matrix(4:7,2,2) +## cachedmat <- makeCacheMatrix(sqmat) +## cacheSolve(cm) +## This routine takes a matrix as input and exposes +## routines which allow cacheSolve to fetch cached +## inverted matrix copy, if it already exists. makeCacheMatrix <- function(x = matrix()) { - + m <- NULL + set <- function(y) { + x <<- y + m <<- NULL + } + get <- function() x + setsolve <- function(solve) m <<- solve + getsolve <- function() m } - -## Write a short comment describing this function +## This routine takes as input a special "cachedMatrix" +## and returns a inverted one cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## Return a matrix that is the inverse of 'x' + m <- x$getsolve() + if(!is.null(m)) { + message("getting cached matrix inversion data") + return(m) + } + data <- x$get() + m <- solve(data, ...) + x$setsolve(m) + m } +