File tree Expand file tree Collapse file tree 1 file changed +40
-15
lines changed Expand file tree Collapse file tree 1 file changed +40
-15
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 ()) {
7
-
8
- }
9
-
10
-
11
- # # Write a short comment describing this function
12
-
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
15
- }
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 ()) {
7
+ m <- NULL
8
+ set <- function (y ) {
9
+ x <<- y
10
+ m <<- NULL
11
+ }
12
+ get <- function () x
13
+ setinverse <- function (solve ) m <<- solve
14
+ getinverse <- function () m
15
+ list (set = set , get = get , setinverse = setinverse , getinverse = getinverse )
16
+
17
+ }
18
+
19
+
20
+ # # Write a short comment describing this function
21
+
22
+ cacheSolve <- function (x , ... ) {
23
+ m <- x $ getinverse()
24
+ if (! is.null(m )) {
25
+ message (" getting cached inverse matrix" )
26
+ return (m )
27
+ }
28
+ message(" Don't have computation cached. Calculating inverse of input matrix..." )
29
+ data <- x $ get()
30
+ m <- solve(data )
31
+ x $ setinverse(m )
32
+ m
33
+ }
34
+
35
+ a <- matrix (c(1 : 9 ), nrow = 3 , ncol = 3 )
36
+ a [[2 ,2 ]] <- 0
37
+ a
38
+ b <- makeCacheMatrix(a )
39
+ cacheSolve(b )
40
+
You can’t perform that action at this time.
0 commit comments