Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 21 additions & 7 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
## 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
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()
}