File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
3-
4- # # Write a short comment describing this function
5-
6- makeCacheMatrix <- function (x = matrix ()) {
7-
8- }
9-
10-
11- # # Write a short comment describing this function
12-
13- cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
15- }
1+ # # The functions below create a special vector that stores a matrix along with
2+ # # its cached inverse if the inverse has been previously solved by cacheSolve
3+ # # below
4+
5+ # # makeCacheMatrix creates a special vector that stores a matrix and its
6+ # # cached inverse if computed.
7+
8+ makeCacheMatrix <- function (x = matrix ()) {
9+ m <- NULL
10+ set <- function (y ) {
11+ x <<- y
12+ m <<- NULL
13+ }
14+ get <- function () x
15+ setmatrix <- function (matrix ) m <<- matrix
16+ getmatrix <- function () m
17+ list (set = set , get = get ,
18+ setmatrix = setmatrix ,
19+ getmatrix = getmatrix )
20+ }
21+
22+ # # cacheSolve checks to see if the inverse of a matrix is stored in the
23+ # # vector created by makeCacheMatrix, if so it returns the stored value
24+ # # if not it computes the inverse and stores the value in the cache.
25+
26+ cacheSolve <- function (x , ... ) {
27+ m <- x $ getmatrix()
28+ if (! is.null(m )) {
29+ message(" getting cached data" )
30+ return (m )
31+ }
32+ data <- x $ get()
33+ m <- solve(data , ... )
34+ x $ setmatrix(m )
35+ m
36+ }
You can’t perform that action at this time.
0 commit comments