File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change
1
+ .Rproj.user
2
+ .Rhistory
3
+ .RData
4
+ ProgrammingAssignment2.Rproj
Original file line number Diff line number Diff line change 1
1
# # Put comments here that give an overall description of what your
2
2
# # functions do
3
3
4
- # # Write a short comment describing this function
4
+ # # Returns an object ( a list of functions ) which will allow
5
+ # # us to operate on a matrix in a number of functional ways
6
+ # # including storing a cached matrix inverse for the given matrix
5
7
6
8
makeCacheMatrix <- function (x = matrix ()) {
7
-
9
+ x_inverse = NULL
10
+ list (
11
+ set = function (y ) {
12
+ x <<- y
13
+ x_inverse <<- NULL
14
+ },
15
+ get = function (){
16
+ x
17
+ },
18
+ setinverse = function (y_inverse ){
19
+ x_inverse <<- y_inverse
20
+ },
21
+ getinverse = function (){
22
+ x_inverse
23
+ }
24
+ )
8
25
}
9
26
10
27
11
- # # Write a short comment describing this function
28
+ # # for a given cacheMatrix (as returned from makeCacheMatrix)
29
+ # # either calculate or return a cache inverse. A cleaner
30
+ # # method may just use a memoise-pattern in the makeCacheMatrix
12
31
13
32
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
33
+ # # Return a matrix that is the inverse of 'x'
34
+ x_inverse = x $ getinverse()
35
+ if (! is.null(x_inverse )) {
36
+ message(" getting cached matrix inverse" )
37
+ return (x_inverse )
38
+ }
39
+ x_matrix = x $ get()
40
+ x_inverse = solve(x_matrix , ... )
41
+ x $ setinverse(x_inverse )
42
+ x_inverse
15
43
}
You can’t perform that action at this time.
0 commit comments