From d5da88b696012234540c3acc7a83889e3f38b177 Mon Sep 17 00:00:00 2001 From: thinkingstill Date: Sun, 21 Dec 2014 20:49:23 +0800 Subject: [PATCH 1/2] Update cachematrix.R this is my assignment. --- cachematrix.R | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..eb48499d46a 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -3,13 +3,32 @@ ## Write a short comment describing this function -makeCacheMatrix <- function(x = matrix()) { - -} +makeCacheMatri <- 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' + +cacheSolve <- function(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 ff551d8b1107bd25576d9865f94f549513bde5a4 Mon Sep 17 00:00:00 2001 From: thinkingstill Date: Wed, 21 Jan 2015 22:29:31 +0800 Subject: [PATCH 2/2] Update cachematrix.R --- cachematrix.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index eb48499d46a..25af371d48e 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,7 +1,7 @@ -## Put comments here that give an overall description of what your -## functions do +## makeCacheMatri creates a special "matrix" object that can cache its inverse. +## cacheSolve computes the inverse of the special "matrix" returned by makeCacheMatrix above -## Write a short comment describing this function +## creates a special "matrix" object that can cache its inverse. makeCacheMatri <- function(x = matrix()) { m <- NULL @@ -18,7 +18,7 @@ makeCacheMatri <- function(x = matrix()) { } -## Write a short comment describing this function +## computes the inverse of the special "matrix" returned by makeCacheMatrix above cacheSolve <- function(x) {