File tree Expand file tree Collapse file tree 1 file changed +30
-5
lines changed Expand file tree Collapse file tree 1 file changed +30
-5
lines changed 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
+ # #
5
+ # # This function creates a special matrix object that is then cached.
6
+ # # When called it creates inver
7
+ # #
5
8
6
9
makeCacheMatrix <- function (x = matrix ()) {
7
-
10
+ m <- NULL
11
+ set <- function (y ) {
12
+ x <<- y
13
+ m <<- NULL
14
+ }
15
+ get <- function () x
16
+ setmatrix <- function (solve ) m <<- solve
17
+ getmatrix <- function () m
18
+ list (set = set , get = get ,
19
+ setmatrix = setmatrix ,
20
+ getmatrix = getmatrix )
8
21
}
9
22
10
23
11
- # # Write a short comment describing this function
12
-
24
+ # #
25
+ # # This function checks for a cached version of the matrix
26
+ # # If it is not cached it computes the inverse of the matrix using the solve() function
27
+ # # This function assumes that the matrix is invertible (square dimensions)
28
+ # #
13
29
cacheSolve <- function (x , ... ) {
14
30
# # Return a matrix that is the inverse of 'x'
15
- solve(x )
31
+ m <- x $ getmatrix()
32
+ if (! is.null(m )) {
33
+ message(" getting cached data" )
34
+ return (m )
35
+ }
36
+ data <- x $ get()
37
+ message(" are we here" )
38
+ m <- solve(data , ... )
39
+ x $ setmatrix(m )
40
+ m
16
41
}
You can’t perform that action at this time.
0 commit comments