File tree Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Expand file tree Collapse file tree 2 files changed +34
-6
lines changed Original file line number Diff line number Diff line change
1
+ .Rproj.user
2
+ .Rhistory
3
+ .RData
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
+ # # A set of functions that aids frequent access of results of matrix inversion operations,
2
+ # # best fit for matrices with large dimensions.
3
3
4
- # # Write a short comment describing this function
4
+ # # Function to create a special matrix whose inversion is cached for subsequent access
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ i <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ i <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinv <- function (inv ) i <<- inv
14
+ getinv <- function () i
15
+ list (set = set , get = get ,
16
+ setinv = setinv ,
17
+ getinv = getinv )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
21
+ # # Function to retrieve the inversion of any matrix created via makeCacheMatrix if already
22
+ # # cached, otherwise calculcates the inversion and cache it for the matrix
12
23
13
24
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
25
+ # # returns NA if x is not properly created via makeCacheMatrix
26
+ if (! " getinv" %in% names(x ) | ! " setinv" %in% names(x )) {
27
+ warning(" input matrix not wrapped by makeCacheMatrix" )
28
+ return (NA )
29
+ }
30
+ # # Return a matrix that is the inverse of 'x'
31
+ i <- x $ getinv()
32
+ if (! is.null(i )) {
33
+ message(" getting cached data" )
34
+ return (i )
35
+ }
36
+ data <- x $ get()
37
+ i <- solve(data , ... ) %*% data
38
+ x $ setinv(i )
39
+ i
15
40
}
You can’t perform that action at this time.
0 commit comments