From 509bfb67d8fbfb849677d8683c91f2e780fafac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ol=C4=99dzki?= Date: Wed, 23 Apr 2014 20:42:44 +0200 Subject: [PATCH 1/4] text clarification --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a8c502a4be..2501a6a4129 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ current environment. Below are two functions that are used to create a special object that stores a numeric vector and caches its mean. The first function, `makeVector` creates a special "vector", which is -really a list containing a function to +really a list containing four functions to 1. set the value of the vector 2. get the value of the vector From 50925ba71015979a635957ba99525f7cc0f6b7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ol=C4=99dzki?= Date: Fri, 25 Apr 2014 22:21:12 +0200 Subject: [PATCH 2/4] Solved --- cachematrix.R | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..48eb086a75a 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,30 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function +## A pair of functions that cache the inverse of a matrix, for the sake of saving time of +## re-calcuating the result on subsequent calls. +## Creates a special wrapper around given matrix, +## which offers a quick (cached) computation of matrix inverse makeCacheMatrix <- function(x = matrix()) { + matrix <- x + inverse <- NULL + getCachedInverse <- function() inverse + getMatrix <- function() matrix + calculateInverseAndStore <-function() { + inverse <<- solve(matrix) + inverse + } + list(getCachedInverse = getCachedInverse, calculateInverseAndStore = calculateInverseAndStore) } -## Write a short comment describing this function +## Returns inverse of a wrapped matrix created with makeCacheMatrix. +## Ensures the matrix inverse is calculated only once and cached for subsequent calls. +cacheSolve <- function(cacheMatrix, ...) { + candidate <- cacheMatrix$getCachedInverse() + if (!is.null(candidate)) { + message("from cache") + return (candidate) + } -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' + cacheMatrix$calculateInverseAndStore() } From 85925b3bb4275f551f048394b92ddfca308886a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ol=C4=99dzki?= Date: Fri, 25 Apr 2014 22:23:05 +0200 Subject: [PATCH 3/4] Redundant line removed --- cachematrix.R | 1 - 1 file changed, 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index 48eb086a75a..358df169183 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -8,7 +8,6 @@ makeCacheMatrix <- function(x = matrix()) { inverse <- NULL getCachedInverse <- function() inverse - getMatrix <- function() matrix calculateInverseAndStore <-function() { inverse <<- solve(matrix) inverse From 500805480ac0769223221055afa00a31cffd47f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ol=C4=99dzki?= Date: Mon, 28 Apr 2014 10:58:35 +0200 Subject: [PATCH 4/4] LICENSE added --- LICENSE | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000000..2b20e9e93b2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2014, Grzegorz Oledzki + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file