From 6a486faacbf1ecfbcec53dbe73a2f9363d62b019 Mon Sep 17 00:00:00 2001 From: ILH Date: Tue, 22 Apr 2014 18:21:04 +0200 Subject: [PATCH] done --- cachematrix.R | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..5135b0680b4 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -4,7 +4,17 @@ ## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + i = NULL + set = function(y) { + x <<- y + i <<- NULL + + } + get = function() x + setsolve = function(solve) i <<- solve + getsolve = function() i + list (set=set, get=get, setsolve=setsolve, getsolve=getsolve) + } @@ -12,4 +22,14 @@ makeCacheMatrix <- function(x = matrix()) { cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' + i = x$getsolve() + if(!is.null(i)){ + message ("getting cached data") + return (i) + } + + data= x$get() + i = solve(data) + x$setsolve(i) + i }