Skip to content

Commit 48825a3

Browse files
committed
completed function
1 parent 7f657dd commit 48825a3

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

cachematrix.R

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
# This script does 2 things:
2+
# 1. it stores data into an object and initializes a "storage space" for a computation performed on said data
3+
# 2. it performs computation on the vector, returns an answer, and stores the answer in the storage space
34

4-
## Write a short comment describing this function
5-
6-
makeCacheMatrix <- function(x = matrix()) {
5+
################################################################################
6+
# Assignment 2
7+
################################################################################
78

9+
makeCacheMatrix <- function(x = matrix()) { # The function where data is stored and "stotage" or cache is initialized
10+
inv <- NULL
11+
set <- function(y) {
12+
x <<- y
13+
m <<- NULL
14+
}
15+
get <- function() x
16+
setinv <- function(inverse) inv <<- inverse
17+
getinv <- function() inv
18+
list(set = set, get = get,
19+
setinv = setinv,
20+
getinv = getinv)
821
}
922

10-
11-
## Write a short comment describing this function
12-
13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
23+
cacheSolve <- function(x, ...) { # A function that solves the inverse of a matrix 'x', the inverse is stored in makeCasheMatrix for fast retrival
24+
inv <- x$getinv()
25+
if(!is.null(inv)) {
26+
message("getting cached data")
27+
return(inv)
28+
}
29+
data <- x$get()
30+
inv <- solve(data, ...)
31+
x$setinv(inv)
32+
inv
1533
}
34+

0 commit comments

Comments
 (0)