Skip to content

Commit 4dc5701

Browse files
committed
programming assignment initial commit
1 parent 7f657dd commit 4dc5701

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

cachematrix.R

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
## Put comments here that give an overall description of what your
22
## functions do
3-
43
## Write a short comment describing this function
5-
4+
## This creates a cachematrix object where x is defined as a matrix
65
makeCacheMatrix <- function(x = matrix()) {
7-
6+
## NULL is assigned the variable m
7+
m <- NULL
8+
## Sets the value of the matrix
9+
set <- function(y) {
10+
## y is superassigned x which is defined as a matrix
11+
x <<- y
12+
## NULL is superassigned to m
13+
m <<- NULL
14+
}
15+
## Get the value of the matrix depending on the supplied vector
16+
get <- function() x
17+
## Sets the value and gets the value of the inverse
18+
setinverse <- function(solve) m <<- solve
19+
getinverse <- function() m
20+
list(set = set, get = get,
21+
setinverse = setinverse,
22+
getinverse = getinverse)
823
}
924

10-
11-
## Write a short comment describing this function
12-
25+
## cacheSolve function takes the arguments x, in this case a matrix,and ...
1326
cacheSolve <- function(x, ...) {
1427
## Return a matrix that is the inverse of 'x'
28+
## gets the inverse of the matrix and assigns it to m
29+
m <- x$getinverse()
30+
31+
## if m is NOT a null value, previously solved, then print message
32+
if(!is.null(m)) {
33+
message("getting cached data")
34+
return(m)
35+
}
36+
## otherwise assign the get function a name 'data'
37+
data <- x$get()
38+
## and passes in 'data' as an argument in the solve function assigned to m
39+
m <- solve(data, ...)
40+
## ...which sets the inverse of the cached matrix
41+
x$setinverse(m)
42+
m
1543
}
44+

0 commit comments

Comments
 (0)