File tree Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Expand file tree Collapse file tree 1 file changed +34
-6
lines changed 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
1
+ # # These functions have been developed as part of a Coursera R Programming course
2
+ # # assignment.
3
3
4
- # # Write a short comment describing this function
4
+ # # Creates a set of utility functions to work with a matrix and cache the results of
5
+ # # inverting it. It's assumed the matrix is always invertible.
5
6
6
7
makeCacheMatrix <- function (x = matrix ()) {
7
-
8
+ s <- NULL
9
+
10
+ set <- function (y ) {
11
+ x <<- y
12
+ s <<- NULL
13
+ }
14
+
15
+ get <- function () x
16
+
17
+ setsolve <- function (solve ) s <<- solve
18
+
19
+ getsolve <- function () s
20
+
21
+ list (set = set , get = get ,
22
+ setsolve = setsolve ,
23
+ getsolve = getsolve )
8
24
}
9
25
10
26
11
- # # Write a short comment describing this function
27
+ # # Inverts a matrix, but caches the result for subsequent invocations.
28
+ # # x should be a list of functions as returned by makeCacheMatrix
12
29
13
30
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
31
+ s <- x $ getsolve()
32
+
33
+ if (! is.null(s )) {
34
+ message(" getting cached data" )
35
+ return (s )
36
+ }
37
+
38
+ data <- x $ get()
39
+ s <- solve(data , ... )
40
+ x $ setsolve(s )
41
+
42
+ s
15
43
}
You can’t perform that action at this time.
0 commit comments