File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
6
+ # # This function will create a matrix function that allows user to set their matrix ($set), read the matrix($get)
7
+ # # This function will also allow user to read the inverse of function ($getinv)
8
+ # # If the result is NULL, then user need to run the cacheSolve() function
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
+ setinv <- function (solve ) m <<- solve
17
+ getinv <- function () m
18
+ list (set = set , get = get ,
19
+ setinv = setinv ,
20
+ getinv = getinv )
8
21
}
9
22
10
-
11
23
# # Write a short comment describing this function
12
24
25
+ # # If makeCacheMatrix$getinv() is NULL, then user need to run the following function
26
+ # # This function will compute the inverse of matrix and store the result to the function that was
27
+ # # previously created in makeCachematric()
28
+
29
+
13
30
cacheSolve <- function (x , ... ) {
14
31
# # Return a matrix that is the inverse of 'x'
32
+ m <- x $ getinv()
33
+ if (! is.null(m )) {
34
+ message(" getting cached data" )
35
+ return (m )
36
+ }
37
+ data <- x $ get()
38
+ m <- solve(data , ... )
39
+ x $ setinv(m )
40
+ m
15
41
}
You can’t perform that action at this time.
0 commit comments