forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
My answer to the second programming assignment version rdpeng#1
- Loading branch information
1 parent
7f657dd
commit a54fefb
Showing
1 changed file
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
## Put comments here that give an overall description of what your | ||
## functions do | ||
## These functions combined, will be able to return an inverse of a matrix. | ||
## The function is written so that, should a matrix have remained the same, it will returned it's previously cached result, rather than computing the inverse again, | ||
## making the solution more efficient. | ||
|
||
## Write a short comment describing this function | ||
## makeCachematrix creates a 'special' matrix out of a simple matrix and makes it able to store the inverse in the cached memory | ||
|
||
makeCacheMatrix <- function(x = matrix()) { | ||
|
||
m <- NULL | ||
set <- function(y){ | ||
x <<- y | ||
m <<- NULL | ||
} | ||
get <- function() x | ||
setsolve <- function(solve) m <<- solve | ||
getsolve <- function() m | ||
list(set = set, get = get, setsolve = setsolve, getsolve = getsolve) | ||
} | ||
|
||
|
||
## Write a short comment describing this function | ||
## cacheSolve checks to see if the special matrix matches the special matrix from the previously cached inverse, and returns the cached inverse if true. | ||
## Should the special matrix have been altered, it computes and returns the appropriate inverse. | ||
|
||
cacheSolve <- function(x, ...) { | ||
## Return a matrix that is the inverse of 'x' | ||
m <- x$getsolve() | ||
if(!is.null(m)){ | ||
message("getting cached data") | ||
return(m) | ||
} | ||
data <- x$get() | ||
m <- solve(data,...) | ||
x$setsolve(m) | ||
m | ||
} |