Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0adf4ae

Browse files
committed
Add function definitions
1 parent 7f657dd commit 0adf4ae

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

cachematrix.R

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

4-
## Write a short comment describing this function
5-
6-
makeCacheMatrix <- function(x = matrix()) {
2+
## Create an object to store a matrix and its' inverse
73

4+
makeCacheMatrix <- function(m = matrix()) {
5+
i <- NULL
6+
set <- function(y) {
7+
m <<- y
8+
inv <<- NULL
9+
}
10+
get <- function() m
11+
setinv <- function(inv) i <<- inv
12+
getinv <- function() i
13+
list(set = set, get = get,
14+
setinv = setinv,
15+
getinv = getinv)
816
}
917

1018

11-
## Write a short comment describing this function
19+
## Chave the inverse of a matrix using an objetc
20+
## returned by makeCacheMatrix
1221

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

0 commit comments

Comments
 (0)