Skip to content

Commit 3139d13

Browse files
committed
finishing assignment 2 attempt 2
1 parent 7f657dd commit 3139d13

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

cachematrix.R

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## Assignment 2
32

4-
## Write a short comment describing this function
3+
## makes a matrix inside a list, for x I used x = replicate(10, rnorm(10))
54

65
makeCacheMatrix <- function(x = matrix()) {
6+
m <- NULL
7+
set <- function(y) {
8+
x <<- y
9+
m <<- NULL
10+
}
11+
get <- function() x
12+
setinv <- function(inv) m <<- inv
13+
getinv <- function() m
14+
list(set = set, get = get,
15+
setinv = setinv,
16+
getinv = getinv)
717

818
}
919

1020

11-
## Write a short comment describing this function
21+
## cache de inverse of the matrix made in de previous function
1222

1323
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
24+
m <- x$getinv()
25+
if(!is.null(m)) {
26+
message("getting cached data")
27+
return(m)
28+
}
29+
data <- x$get()
30+
m <- solve(data, ...)
31+
x$setinv(m)
32+
m
1533
}

0 commit comments

Comments
 (0)