From a7f0054cfc687fd9877dc7d0da692db97357bd2c Mon Sep 17 00:00:00 2001 From: THN1Q Date: Fri, 25 Apr 2014 00:44:53 +0300 Subject: [PATCH 1/3] Solution applied. --- ProgrammingAssignment2 | 1 + 1 file changed, 1 insertion(+) create mode 160000 ProgrammingAssignment2 diff --git a/ProgrammingAssignment2 b/ProgrammingAssignment2 new file mode 160000 index 00000000000..e4eed4153bd --- /dev/null +++ b/ProgrammingAssignment2 @@ -0,0 +1 @@ +Subproject commit e4eed4153bd237a2dd4532fc3f40ce0e22fd0cb7 From 0f482998f24c5dec64ba2720785cdef64f39acf6 Mon Sep 17 00:00:00 2001 From: THN1Q Date: Fri, 25 Apr 2014 00:55:27 +0300 Subject: [PATCH 2/3] Solution applied. --- .Rhistory | 0 cachematrix.R | 55 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .Rhistory diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..45cf9bb80fe 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,56 @@ -## Put comments here that give an overall description of what your -## functions do +## A set of functions which calculate and cache the inverse of a matrix for +## later usage. -## Write a short comment describing this function +## This function creates a special "matrix" object that can cache its inverse. makeCacheMatrix <- function(x = matrix()) { + + i <- NULL + + ## this object stores the inverse of the matrix + + set <- function(y) { + x <<- y + inverse <<- NULL + } + + ## stores the matrix in the global environment and resets inverse matrix + + get <- function () x + + ## prints the matrix + + setinverse <- function(inverse) i <<- inverse + + ## stores inverse matrix of x in the global environment + + getinverse <- function() i + + ## prints inverse matrix of x + + list(set = set, get = get, + setinverse = setinverse, + getinverse = getinverse) + ## function interface for makeCacheMatrix } - -## Write a short comment describing this function +## This function computes the inverse of the special "matrix" returned by +## makeCacheMatrix. If the inverse has already been calculated, it retrieves +## the inverse from the cache. cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' -} + + i <- x$getinverse() + if(!is.null(i)) { + message("getting cached data") + return(i) + } + + ## checks for cached inverse matrix of x and returns it if available + + data <- x$get() ## retrieves original matrix + i <- solve(data, ...) ## calculates inverse matrix of x + x$setinverse(i) ## stores calculated inverse matrix in GE + i ## printes inverse matrix +} \ No newline at end of file From a710b8912c0cd42069d7ae095fc0262dd3d478a1 Mon Sep 17 00:00:00 2001 From: THN1Q Date: Fri, 25 Apr 2014 00:56:58 +0300 Subject: [PATCH 3/3] Solution applied. --- .Rhistory | 0 ProgrammingAssignment2 | 1 - 2 files changed, 1 deletion(-) delete mode 100644 .Rhistory delete mode 160000 ProgrammingAssignment2 diff --git a/.Rhistory b/.Rhistory deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/ProgrammingAssignment2 b/ProgrammingAssignment2 deleted file mode 160000 index e4eed4153bd..00000000000 --- a/ProgrammingAssignment2 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e4eed4153bd237a2dd4532fc3f40ce0e22fd0cb7