Skip to content

Commit ef57772

Browse files
committed
2n assignment with comments and corrections
1 parent 61e2cef commit ef57772

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cachematrix.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,52 @@
33

44
makeCacheMatrix <- function(x = matrix()) {
55

6+
#set the value of the cache matrix to null
67
cachematrix <- NULL
78

9+
#function to set the value of the matrix
810
set <- function(mtrx) {
911
x <<- mtrx
1012
cachematrix <<- NULL
1113
}
1214

15+
#function to get the matrix data
1316
get <- function() {
1417
x
1518
}
1619

20+
#set the matrix and cache
1721
setmatrix <- function(pmatrix) {
1822
cachematrix <<- pmatrix
1923
}
2024

25+
#get the value of the matrix
2126
getmatrix <- function() {
22-
cachematrix> a <- makeCacheMatrix(matrix(1:4,2))
27+
cachematrix
2328
}
2429

30+
#organize everything as a list
2531
list(set = set, get = get,
2632
setmatrix = setmatrix,
2733
getmatrix = getmatrix)
2834
}
2935

3036

3137

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
3439

3540
cacheSolve <- function(x, ...) {
41+
42+
#gets the value of the matrix
3643
m <- x$getmatrix()
44+
45+
#if there is a cache retrieves the value
3746
if(!is.null(m)) {
3847
message("getting cached data")
3948
return(m)
4049
}
50+
51+
#returns the reverse of the matrix
4152
data <- x$get()
4253
m <- solve(data, ...)
4354
x$setmatrix(m)

0 commit comments

Comments
 (0)