Skip to content

Commit ccf3086

Browse files
author
Marcus Teixeira
committed
Functions makeCacheMatrix and cacheSolve completed.
1 parent 7f657dd commit ccf3086

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

cachematrix.R

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,37 @@
33

44
## Write a short comment describing this function
55

6-
makeCacheMatrix <- function(x = matrix()) {
7-
6+
makeCacheMatrix <- function( dataMatrix = matrix() ) {
7+
inverseMatrix <- NULL
8+
9+
set <- function( newDataMatrix ) {
10+
dataMatrix <<- newDataMatrix
11+
inverseMatrix <<- NULL
12+
}
13+
14+
get <- function() dataMatrix
15+
16+
setInverse <- function( inverse ) inverseMatrix <<- inverse
17+
18+
getInverse <- function() inverseMatrix
19+
20+
list(set = set, get = get,
21+
setInverse = setInverse,
22+
getInverse = getInverse)
823
}
924

1025

1126
## Write a short comment describing this function
1227

1328
cacheSolve <- function(x, ...) {
1429
## Return a matrix that is the inverse of 'x'
30+
inverse <- x$getInverse()
31+
if ( !is.null( inverse ) ) {
32+
message( "Getting cached data..." )
33+
return( inverse )
34+
}
35+
data <- x$get()
36+
inverse <- solve( data, ... )
37+
x$setInverse( inverse )
38+
inverse
1539
}

0 commit comments

Comments
 (0)