Skip to content

Commit 979fb86

Browse files
committed
added implementations for both functions
1 parent 7f657dd commit 979fb86

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

cachematrix.R

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
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
72

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)
816
}
917

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
1530
}

0 commit comments

Comments
 (0)