Skip to content

Commit 22eaa35

Browse files
committed
Programming Assignment2 ver 0.5
1 parent 7f657dd commit 22eaa35

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

cachematrix.R

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## Cache the inverse of a matrix.
32

4-
## Write a short comment describing this function
3+
## Create a special matrix which can store its inverse.
54

65
makeCacheMatrix <- function(x = matrix()) {
7-
6+
m <- NULL
7+
set <- function(y){
8+
x <<- y
9+
m <<- NULL
10+
}
11+
get <- function() x
12+
setInverse <- function(solve) m <<- solve
13+
getInverse <- function() m
14+
list(set = set, get = get,
15+
setInverse = setInverse,
16+
getInverse = getInverse)
817
}
918

1019

11-
## Write a short comment describing this function
20+
## Before compute the inverse of matrix x, see if x has it cached , and return that if do.
1221

1322
cacheSolve <- function(x, ...) {
1423
## Return a matrix that is the inverse of 'x'
24+
m <- x$getInverse()
25+
if (!is.null(m)) {
26+
message("getting cached data")
27+
return (m)
28+
}
29+
data <- x$get()
30+
m <- solve(data)
31+
x$setInverse(m)
32+
m
1533
}
34+
35+
36+

0 commit comments

Comments
 (0)