Skip to content

Commit fb3fa8a

Browse files
committed
Created the functions for the assignement
1 parent 7f657dd commit fb3fa8a

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

cachematrix.R

Lines changed: 24 additions & 5 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+
## A couple of functions that can cache and create an inverse of a matrix
32

4-
## Write a short comment describing this function
53

4+
## This function creates a special "matrix" object that can cache its inverse.
65
makeCacheMatrix <- function(x = matrix()) {
76

7+
inversedMatrix <- NULL
8+
9+
set <- function(y) {
10+
x <<- y
11+
inversedMatrix <<- NULL
12+
}
13+
get <- function() x
14+
15+
setInverse <- function(inverse) inversedMatrix <<- inverse
16+
getInverse <- function() inversedMatrix
17+
18+
list(set = set, get = get,
19+
setInverse = setInverse,
20+
getInverse = getInverse)
821
}
922

1023

11-
## Write a short comment describing this function
12-
24+
## This function creates an inverse of the matrix x. Unless the inverse is
25+
## already created, then it returns the cached inversed matrix.
1326
cacheSolve <- function(x, ...) {
1427
## Return a matrix that is the inverse of 'x'
28+
inverse = x$getInverse()
29+
if (is.null(inverse)) {
30+
inverse = solve(x$get())
31+
x$setInverse(inverse)
32+
}
33+
inverse
1534
}

0 commit comments

Comments
 (0)