1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # makeCacheMatrix creates special "matrix" whereas the cacheSolve returns the inverse of the
2
+ # # matrix from cache, if it exists there. if not, it computes the inverse and returns it.
3
3
4
- # # Write a short comment describing this function
4
+ # # makeCacheMatrix creates a special "matrix" ,which is a list containing a function to
5
+ # # 1. set the value of the matrix
6
+ # # 2. get the value of the matrix
7
+ # # 3. set the inverse of the matrix
8
+ # # 4. get the inverse of the matrix
5
9
6
10
makeCacheMatrix <- function (x = matrix ()) {
7
11
inv <- NULL
@@ -19,7 +23,8 @@ makeCacheMatrix <- function(x = matrix()) {
19
23
}
20
24
21
25
22
- # # Write a short comment describing this function
26
+ # # cacheSolve returns the inverse of a matrix if it exists in the cache.
27
+ # # if not, it computes the inverse and returns it
23
28
24
29
cacheSolve <- function (x , ... ) {
25
30
# # Return a matrix that is the inverse of 'x'
@@ -34,6 +39,8 @@ cacheSolve <- function(x, ...) {
34
39
inv
35
40
}
36
41
42
+ # # Test both functions with test data
37
43
a = matrix ( c(4 ,10 ,23 ,12 ), nrow = 2 , ncol = 2 )
38
44
mat <- makeCacheMatrix(a )
39
45
cacheSolve(mat )
46
+ cacheSolve(mat )
0 commit comments