diff --git a/assignment2 b/assignment2 new file mode 100644 index 00000000000..d9c1a526b21 --- /dev/null +++ b/assignment2 @@ -0,0 +1,55 @@ +## The function creates a special "matrix" object that can cache its inverse. + +makeCacheMatrix <- function(x = matrix()) { + + inv <- NULL + + set <- function(y) { + + x <<- y + + inv <<- NULL + + } + + get <- function() x + + setinverse <- function(inverse) inv <<- inverse + + getinverse <- function() inv + + list(set = set, + + get = get, + + setinverse = setinverse, + + getinverse = getinverse) + +} + + +## The function calculates the mean of the special "vector" created with the above function + +cacheSolve <- function(x, ...) { + + inv <- x$getinverse() + + if(!is.null(inv)) { + + message("getting cached data") + + return(inv) + + } + + mat <- x$get() + + inv <- solve(mat, ...) + + x$setinverse(inv) + + inv + +} +