File tree Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Expand file tree Collapse file tree 1 file changed +24
-8
lines changed Original file line number Diff line number Diff line change 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.
6
3
makeCacheMatrix <- function (x = matrix ()) {
4
+ matrix <- x
5
+ inversion <- NULL
6
+ set <- function (x ) {
7
+ matrix <<- x
8
+ inversion <<- NULL
9
+ }
7
10
11
+ get <- function () { matrix }
12
+ setinversion <- function (solved ) { inversion <<- solved }
13
+ getinversion <- function () { inversion }
14
+ list (set = set , get = get , setinversion = setinversion , getinversion = getinversion )
8
15
}
9
16
10
17
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
+ }
12
27
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 )
15
31
}
You can’t perform that action at this time.
0 commit comments