From f41183ef1723f0982bff5cd98403010ada6a3c4f Mon Sep 17 00:00:00 2001 From: olarina Date: Tue, 19 Feb 2019 14:20:47 +0100 Subject: [PATCH 1/3] Test commit --- cachematrix.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..62fcd9ca430 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,7 +4,7 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - +##test } From 160920462aa094229caa0fd9f581e8d5bb99b6db Mon Sep 17 00:00:00 2001 From: olarina Date: Wed, 20 Feb 2019 10:27:57 +0100 Subject: [PATCH 2/3] cachematrix.R commit --- cachematrix.R | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 62fcd9ca430..0e792a0b732 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,44 @@ -## Put comments here that give an overall description of what your -## functions do +## Below are two functions that are used to create a special object that stores +## a numeric matrix and caches its inversion -## Write a short comment describing this function +## The first function, makeCacheMatrix creates a special "vector" +## which is really a list containing a function to -makeCacheMatrix <- function(x = matrix()) { -##test -} +## 1. set the value of the matrix +## 2. get the value of the matrix +## 3. set the value of the inversion +## 4. get the value of the inversion +makeCacheMatrix <- function(x = matrix()) +{ + inv <- NULL + set <- function(y) + { + x <<- y + inv <<- NULL + } + get <- function() x + setinv <- function(i) inv <<- i + getinv <- function() inv + list(set = set, get = get, setinv = setinv, getinv = getinv) +} -## Write a short comment describing this function +## The following function calculates the inversion of the special "vector" +## created with the makeCacheMatrix function. It first checks if the inversion +## has already been calculated. If so, it gets the inversion from the cache and +## skips the computation. Otherwise, it calculates the inversion of the data +## and sets the value of the inversion in the cache via the setinv function. -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' +cacheSolve <- function(x, ...) +{ + inv <- x$getinv() + if (!is.null(inv)) + { + message("getting cached data") + return(inv) + } + data <- x$get() + inv <- solve(data, ...) + x$setinv(inv) + inv } From 3b604e1c84ffe3261823a35d810c0a05cceaf8e2 Mon Sep 17 00:00:00 2001 From: olarina Date: Wed, 20 Feb 2019 10:50:50 +0100 Subject: [PATCH 3/3] cachematrix.R update --- cachematrix.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index 0e792a0b732..62616116cbf 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,7 +1,7 @@ ## Below are two functions that are used to create a special object that stores ## a numeric matrix and caches its inversion -## The first function, makeCacheMatrix creates a special "vector" +## The first function, makeCacheMatrix creates a special "matrix" ## which is really a list containing a function to ## 1. set the value of the matrix @@ -23,7 +23,7 @@ makeCacheMatrix <- function(x = matrix()) list(set = set, get = get, setinv = setinv, getinv = getinv) } -## The following function calculates the inversion of the special "vector" +## The following function calculates the inversion of the special "matrix" ## created with the makeCacheMatrix function. It first checks if the inversion ## has already been calculated. If so, it gets the inversion from the cache and ## skips the computation. Otherwise, it calculates the inversion of the data