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

Skip to content

Commit fe00d77

Browse files
committed
Solves the assignment.
1 parent 7f657dd commit fe00d77

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

cachematrix.R

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
5-
1+
## makeCacheMatrix creates an object vid functions to get and set the matrix
2+
## and to get and set the inversion.
63
makeCacheMatrix <- function(x = matrix()) {
4+
matrix <- x
5+
inversion <- NULL
6+
set <- function(x) {
7+
matrix <<- x
8+
inversion <<- NULL
9+
}
710

11+
get <- function() { matrix }
12+
setinversion <- function(solved) { inversion <<- solved }
13+
getinversion <- function() { inversion }
14+
list(set = set, get = get, setinversion = setinversion, getinversion = getinversion)
815
}
916

1017

11-
## Write a short comment describing this function
18+
## Takes an matrix as argument and returns the inversion of it
19+
## if the inversion is alread calculated it returns the cached value
20+
## otherwise it sets it and clears the cache.
21+
cacheSolve <- function(x) {
22+
inversion <- x$getinversion()
23+
24+
if (!is.null(inversion)) {
25+
inversion
26+
}
1227

13-
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
28+
matrix <- x$get()
29+
inversion <- solve(matrix)
30+
x$setinversion(inversion)
1531
}

0 commit comments

Comments
 (0)