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
44 lines (38 loc) · 1.44 KB
/
cachematrix.R
File metadata and controls
44 lines (38 loc) · 1.44 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
## Two functions below is to calculate inverse matrix passed
## to makeCacheMatrix function. Once the inversion of matrix is
## calculated, the inversed matrix is cached into memory.
## If the cached inversion matrix is found, the cached matrix will be
## returned instead of recalculating the inversed matrix again.
## This function is to make a list of four functions which
## are related to inversion of matrix.
## input : inversible matrix
## output : special matrix whch can cache a inversed matrix
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y) {
x <<- y
inv <<- NULL
}
get <- function() x
setinverse <- function(inverse) inv <<- inverse
getinverse <- function() inv
list(get=get, set=set, getinverse=getinverse,
setinverse=setinverse)
}
## This function is to return inversed matrix from the given
## special list returned from makeCacheMatrix().
## If the inversed matrix is found in cache, it will return.
## Otherwise, it will calculate inversed matrx and return it
## after cacheing it.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
m <- x$getinverse()
if (!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$get()
m <- solve(data,...)
x$setinverse(m)
m
}