Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f26c7f

Browse files
committed
Finishing my homework
1 parent 7f657dd commit 2f26c7f

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

cachematrix.R

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## This is a pair of functions for calculating, caching,
2+
## and retrieving the inverse of a square matrix.
33

4-
## Write a short comment describing this function
4+
## makeCacheMatrix is a functional interface to the inverse
5+
## matrix cache, providing a means of retrieving and setting
6+
## inverse matrix values.
57

68
makeCacheMatrix <- function(x = matrix()) {
7-
9+
m <- NULL
10+
set <- function(y) {
11+
x <<- y
12+
m <<- NULL
13+
}
14+
get <- function() x
15+
setsolve <- function(solve) m <<- solve
16+
getsolve <- function() m
17+
list(set = set, get = get,
18+
setsolve = setsolve,
19+
getsolve = getsolve)
820
}
921

1022

11-
## Write a short comment describing this function
23+
## cacheSolve takes a matrix and returns the inverse in one of
24+
## two ways: (1) retrieves it from the cache, or (2) computes
25+
## it and stores the result in the cache before returning it.
1226

1327
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
28+
## Return a matrix that is the inverse of 'x'
29+
m <- x$getsolve()
30+
if(!is.null(m)) {
31+
message("getting cached data")
32+
return(m)
33+
}
34+
data <- x$get()
35+
m <- solve(data, ...)
36+
x$setsolve(m)
37+
m
1538
}

0 commit comments

Comments
 (0)