forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
40 lines (30 loc) · 758 Bytes
/
cachematrix.R
File metadata and controls
40 lines (30 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Put comments here that give an overall description of what your
## functions do
## Write a short comment describing this function
makeCacheMatrix <- function(x = matrix()) {
my_v <- NULL ## inverse matrix
if (!is.matrix(x))
x <- as.matrix(x)
set <- function(newX) {
x <<- newX
my_v <<- NULL
print("set new")
}
get <- function() x
setMy_v <- function(i) my_v <<- i
getMy_v <- function() my_v
list(set=set,
get=get,
setMy_v=setMy_v,
getMy_v=getMy_v)
}
## Write a short comment describing this function
cacheSolve <- function(x, ...) {
my_v <- x$getMy_v()
if (is.null(my_v)) {
m <- x$get()
my_v <- solve(m, ...)
}
x$setMy_v(my_v)
my_v
}