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
29 lines (27 loc) · 903 Bytes
/
Copy pathcachematrix.R
File metadata and controls
29 lines (27 loc) · 903 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
makeCacheMatrix <- function(x = matrix()) {
## create a list to store the matrix and related inversed maxrix
m <- NULL # assigning local m standing for inversed matrix to NULL
set <- function(y){
x <<- y ## <<- is an analog of <-, but it is to assign to global enviroment
m <<- NULL ## totally crush m
}
get <- function() x # subfunction returning initial matrix
setsolve <- function(solve) m <<- solve # subfunction to cache the inverse matrix
getsolve <- function() m # extract the cache
list(set= set, get = get,
setsolve = setsolve,
getsolve = getsolve)
}
cacheSolve <- function(x, ...) {
m <- x$getsolve()
if (!is.null(m)) # check if cache available
{
message("getting cached data")
return(m) #exit cacheSolve and return cache
}
message("computing the cache")
data <- x$get() #intermediate variable
m <- solve(data, ...)
x$setsolve(m)
m
}