From efb94be651b012422a8d805ac0789c2b9ebd7667 Mon Sep 17 00:00:00 2001 From: may-data-scientist-toolbox Date: Sun, 20 Apr 2014 11:35:08 +0200 Subject: [PATCH 1/3] peer assigment --- cachematrix.R | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..f1fb77aa0b5 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,43 @@ ## Put comments here that give an overall description of what your -## functions do - +## functions do. +## I have two functions, makeCacheMatrix and cacheSolve, to get an +## invertible matrix, calculate its inverse and cache the inverse +## calculation. +## ## Write a short comment describing this function +## makeCacheMatrix --- This function sets and gets the matrix, +## and its inverse. makeCacheMatrix <- function(x = matrix()) { - + inv <- NULL + set <- function(y) { + x <<- y + inv <<- NULL + } + get <- function() x + setinverse <- function(solve) inv <<- solve + getinverse <- function() inv + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) } ## Write a short comment describing this function - +## +## cacheSolve --- This function gets the matrix from above and +## gets the cached (already calculated) inverse of this matrix, +## skipping the calculation of inverse again. +## cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + ## Return a matrix that is the inverse of 'x' + inv <- x$getinverse() + if(!is.null(inv)) { + message("getting cached inverse") + return(inv) + } + data <- x$get() + inv <- solve(data, ...) + x$setinverse(inv) + inv } From 5c22dc4ee4e1cd5433d50d5ec7d9d5e22adddf4d Mon Sep 17 00:00:00 2001 From: may-data-scientist-toolbox Date: Sun, 20 Apr 2014 11:53:34 +0200 Subject: [PATCH 2/3] Peer Assignment of R Programming @ Coursera --- cachematrix.R | 1 + 1 file changed, 1 insertion(+) diff --git a/cachematrix.R b/cachematrix.R index f1fb77aa0b5..82befbd33e2 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,5 +1,6 @@ ## Put comments here that give an overall description of what your ## functions do. +## repo: may-data-scientist-toolbox/ProgrammingAssignment2 ## I have two functions, makeCacheMatrix and cacheSolve, to get an ## invertible matrix, calculate its inverse and cache the inverse ## calculation. From b198c1e013eefc10f2dc0d7af9b67668e47166b0 Mon Sep 17 00:00:00 2001 From: may-data-scientist-toolbox Date: Sat, 26 Apr 2014 09:24:56 +0200 Subject: [PATCH 3/3] Update cachematrix.R --- cachematrix.R | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 82befbd33e2..9ed2eac198c 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,11 +1,10 @@ -## Put comments here that give an overall description of what your -## functions do. +## ## repo: may-data-scientist-toolbox/ProgrammingAssignment2 ## I have two functions, makeCacheMatrix and cacheSolve, to get an ## invertible matrix, calculate its inverse and cache the inverse ## calculation. ## -## Write a short comment describing this function +## ## makeCacheMatrix --- This function sets and gets the matrix, ## and its inverse. @@ -24,7 +23,7 @@ makeCacheMatrix <- function(x = matrix()) { } -## Write a short comment describing this function +## ## ## cacheSolve --- This function gets the matrix from above and ## gets the cached (already calculated) inverse of this matrix,