File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 3
3
4
4
makeCacheMatrix <- function (x = matrix ()) {
5
5
6
+ # set the value of the cache matrix to null
6
7
cachematrix <- NULL
7
8
9
+ # function to set the value of the matrix
8
10
set <- function (mtrx ) {
9
11
x <<- mtrx
10
12
cachematrix <<- NULL
11
13
}
12
14
15
+ # function to get the matrix data
13
16
get <- function () {
14
17
x
15
18
}
16
19
20
+ # set the matrix and cache
17
21
setmatrix <- function (pmatrix ) {
18
22
cachematrix <<- pmatrix
19
23
}
20
24
25
+ # get the value of the matrix
21
26
getmatrix <- function () {
22
- cachematrix > a <- makeCacheMatrix( matrix ( 1 : 4 , 2 ))
27
+ cachematrix
23
28
}
24
29
30
+ # organize everything as a list
25
31
list (set = set , get = get ,
26
32
setmatrix = setmatrix ,
27
33
getmatrix = getmatrix )
28
34
}
29
35
30
36
31
37
32
- # # Write a short comment describing this function
33
- # # Return a matrix that is the inverse of 'x'
38
+ # # This function returns the value of the inverse of the matrix
34
39
35
40
cacheSolve <- function (x , ... ) {
41
+
42
+ # gets the value of the matrix
36
43
m <- x $ getmatrix()
44
+
45
+ # if there is a cache retrieves the value
37
46
if (! is.null(m )) {
38
47
message(" getting cached data" )
39
48
return (m )
40
49
}
50
+
51
+ # returns the reverse of the matrix
41
52
data <- x $ get()
42
53
m <- solve(data , ... )
43
54
x $ setmatrix(m )
You can’t perform that action at this time.
0 commit comments