File tree Expand file tree Collapse file tree 1 file changed +27
-9
lines changed Expand file tree Collapse file tree 1 file changed +27
-9
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
1
+ # These functions allows a creation of a caching matrix that
2
+ # can calculate and store it's inverse
5
3
4
+ # Constructor, makes a matrix that can cache it's inverse
6
5
makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ inverse <- NULL
7
+ set <- function (y ) {
8
+ x <<- y
9
+ inverse <<- NULL
10
+ }
11
+ get <- function (){ x }
12
+ setinverse <- function (new_inverse ){
13
+ inverse <<- new_inverse
14
+ }
15
+ getinverse <- function (){ inverse }
16
+ list (set = set , get = get ,
17
+ setinverse = setinverse ,
18
+ getinverse = getinverse
19
+ )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
12
-
23
+ # Computes the inverse of a CacheMatrix, and memoizes the result
13
24
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
15
- }
25
+ inverse <- x $ getinverse()
26
+ if (! is.null(inverse )){
27
+ return (inverse )
28
+ }
29
+ data <- x $ get()
30
+ inverse <- solve(data , ... )
31
+ x $ setinverse(inverse )
32
+ inverse
33
+ }
You can’t perform that action at this time.
0 commit comments