From 25eeb2dcab89d2bc88c8fa17b2d3283327183fab Mon Sep 17 00:00:00 2001 From: gimjung <30802635+gimjung@users.noreply.github.com> Date: Tue, 8 Aug 2017 09:15:07 +1000 Subject: [PATCH 1/2] Update cachematrix.R --- cachematrix.R | 56 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 55115b5..b9f589c 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,13 +1,51 @@ -## Put comments here that give an overall description of what your -## functions do -## Write a short comment describing this function +```{r} +## This function computes the special "matrix" +makeCacheMatrix <- function(x = matrix()) { -makeCacheMatrix <- function(x = matrix()) { + i <- NULL -} + set <- function(y) { -## Write a short comment describing this function -cacheSolve <- function(x, ...) { + x <<- y - ## Return a matrix that is the inverse of 'x' -} + i <<- NULL + + } + + get <- function() x + + setinverse <- function(solve) i <<- solve + getinverse <- function() i + + list(set = set, get = get, setinverse = setinverse, getinverse = getinverse) + + } +``` + +```{r} +## This function computes the inverse of the special "matrix" + + +cachesolve <- function(x, ...) { + + j <- x$getinverse() + if(!is.null(j)) { message("getting cached data") + return(j) + } + + matrice <- x$get() + j <- solve(matrice, ...) + x$setinverse(j) + return(j) + } +``` + +```{r} +## Test Matrix + +m <- makeCacheMatrix(matrix(c(3, 5, 7, 9,1,5,7,4,2), 3, 3)) +m$get() +m$getinverse() +cachesolve(m) +cachesolve(m) +``` From 318f8e7a4e5db1a64e9f0d9179b722f04572eb3f Mon Sep 17 00:00:00 2001 From: gimjung <30802635+gimjung@users.noreply.github.com> Date: Tue, 8 Aug 2017 10:07:02 +1000 Subject: [PATCH 2/2] Delete cachematrix.R --- cachematrix.R | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 cachematrix.R diff --git a/cachematrix.R b/cachematrix.R deleted file mode 100644 index b9f589c..0000000 --- a/cachematrix.R +++ /dev/null @@ -1,51 +0,0 @@ -```{r} -## This function computes the special "matrix" -makeCacheMatrix <- function(x = matrix()) { - - i <- NULL - - set <- function(y) { - - x <<- y - - i <<- NULL - - } - - get <- function() x - - setinverse <- function(solve) i <<- solve - getinverse <- function() i - - list(set = set, get = get, setinverse = setinverse, getinverse = getinverse) - - } -``` - -```{r} -## This function computes the inverse of the special "matrix" - - -cachesolve <- function(x, ...) { - - j <- x$getinverse() - if(!is.null(j)) { message("getting cached data") - return(j) - } - - matrice <- x$get() - j <- solve(matrice, ...) - x$setinverse(j) - return(j) - } -``` - -```{r} -## Test Matrix - -m <- makeCacheMatrix(matrix(c(3, 5, 7, 9,1,5,7,4,2), 3, 3)) -m$get() -m$getinverse() -cachesolve(m) -cachesolve(m) -```