File tree Expand file tree Collapse file tree 1 file changed +26
-11
lines changed Expand file tree Collapse file tree 1 file changed +26
-11
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
-
6
- makeCacheMatrix <- function (x = matrix ()) {
1
+ # # Contains function to alow caching of matrix inversion
7
2
3
+ # # creates an object 'cacheMatrix' which can be used by function 'cacheSolve' to solve a a matrix while cahing the result
4
+ makeCacheMatrix <- function (m = matrix ()) {
5
+ inv <- NULL
6
+
7
+ set <- function (new.matrix ) {
8
+ m <<- new.matrix
9
+ inv <<- NULL
10
+ }
11
+
12
+ get <- function () m
13
+ setinv <- function (new.inv ) inv <<- new.inv
14
+ getinv <- function () inv
15
+ list (set = set , get = get ,setinv = setinv ,getinv = getinv )
8
16
}
9
17
10
-
11
- # # Write a short comment describing this function
12
-
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
18
+ # # Solves a matrix and reuses a formeerly cached result, if available
19
+ # # 'cm' need to be an object returned by function 'makeCacheMatrix'
20
+ cacheSolve <- function (cm ,... ) {
21
+ inv <- cm $ getinv()
22
+
23
+ if (! is.null(inv )) {
24
+ return (inv )
25
+ }
26
+ m <- cm $ get()
27
+ inv <- solve(m ,... )
28
+ cm $ setinv(inv )
29
+ inv
15
30
}
You can’t perform that action at this time.
0 commit comments