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
54 lines (43 loc) · 1.1 KB
/
Copy pathcachematrix.R
File metadata and controls
54 lines (43 loc) · 1.1 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
## R Program Assignment 2
## This source is inclused two funtions
##
## makeCacheMatrix (Matrix )
## cacheSolve (output from makeCacheMatrix)
## to make the Inverse of a Matrix
## makeCacheMatrix (matrix)
## example: mat <- matrix(data = c(4,2,7,6), nrow = 2, ncol = 2)
## a<- makeCacheMatrix(mat)
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
y <- NULL
setmatrix <- function(y) {
x <<- y ## cache for matrix
m <<- NULL ## set value to m
}
getmatrix <- function() x
setsolve <- function(solve)
m <<- solve
getsolve <- function() m
## making list for cache
list(setmatrix = setmatrix,
getmatrix = getmatrix,
setsolve = setsolve ,
getsolve = getsolve)
}
## cacheSolve (cached data)
## example: cacheSolve(mat2)
##
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getsolve()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$getmatrix()
x$setmatrix(data)
## computing for solve (matrix inverse)
m <- solve(data, ...)
x$setsolve(m)
m ##return m
}