File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 2
2
# # functions do
3
3
4
4
# # Write a short comment describing this function
5
-
5
+ # # This function caches x and solve (inverse matrix) and return a list of functions which
6
+ # # let get or set them
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
8
s <- NULL
8
9
set <- function (y ) {
@@ -19,16 +20,24 @@ makeCacheMatrix <- function(x = matrix()) {
19
20
20
21
21
22
# # Write a short comment describing this function
22
-
23
+ # # This function gets solve (inverse matrix). If it is not null return solve cached,
24
+ # # otherwise, get data (x), solve it, save it and return it
23
25
cacheSolve <- function (x , ... ) {
24
- # # Return a matrix that is the solve (inverse) of 'x'
26
+ # # Return a matrix that is the solve (inverse) of 'x'
27
+
28
+ # # Get cached solve (inverse matrix)
25
29
s <- x $ getsolve()
30
+ # # Return cached solve in case it is not null
26
31
if (! is.null(s )) {
27
32
message(" getting cached data" )
28
33
return (s )
29
34
}
35
+ # # otherwise, get data (x)
30
36
data <- x $ get()
37
+ # # solve (inverse matrix) data (x)
31
38
s <- solve(data , ... )
39
+ # # save/store calculated s (inverse matrix)
32
40
x $ setsolve(s )
41
+ # # return calculated s (inverse matrix)
33
42
s
34
43
}
You can’t perform that action at this time.
0 commit comments