Skip to content

Commit

Permalink
Solution for the rdpeng#3 week project
Browse files Browse the repository at this point in the history
  • Loading branch information
DisturbedAdd authored and DisturbedAdd committed Feb 8, 2017
1 parent 7f657dd commit 07b23e3
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
## Put comments here that give an overall description of what your
## functions do

## Write a short comment describing this function
# This function creates a special "matrix" object that can cache its inverse.

makeCacheMatrix <- function(x = matrix()) {
# Although the 'set' function is not required in the description of the task
#there can be found a phrase in the description of cacheSolve function
#"(and the matrix has not changed)" implying that the matrix can be changed.

inv <- NULL
set <- function(y) {
x <<- y
inv <<- NULL
}
get <- function() x
setinverse <- function(inv_2)
inv <<- inv_2
getinverse <- function()
inv
list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
}


## Write a short comment describing this function
# This function computes the inverse of the special "matrix" returned by
#makeCacheMatrix above.
# If the inverse has already been calculated (and the matrix has not changed),
#then the cachesolve should retrieve the inverse from the cache

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inv <- x$getinverse()
if(!is.null(inv)) {
message("getting cached data")
return(inv)
}
data <- x$get()
inv <- solve(data, ...)
x$setinverse(inv)
inv
}

0 comments on commit 07b23e3

Please sign in to comment.