-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
50 lines (44 loc) · 1.33 KB
/
cachematrix.R
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
## Put comments here that give an overall description of what your
## functions do
## Write a short comment describing this function
##
makeCacheMatrix <- function(x = matrix()) {
## Holds the cache value or if nothing is cached
cache <- NULL
##seting matrix
## building matrix --set--
set <- function(y) {
x <<- y
cache <<- NULL
}
## building matrix --get--
get <- function() {
x
}
## building matrix --cacheInv--
cacheInv <- function(solve) {
cache <<- solve
}
## building matrix --getInv--
getInv <- function() {
cache
}
## get a list - naming fuction for each element of the list
list(set = set, get = get, cacheInv = cacheInv, getInv = getInv)
}
## Write a short comment describing this function
## following function calculates the inverse of matrix created above "makeCacheMatrix"
## create function cacheSolve
cacheSolve <- function(y, ...) {
## get cache value if it is in cache
inverse <- y$getInv()
if(!is.null(inverse)) {
## Display msg if data is cached!
message("-- getting cached data --")
return(inverse)
}
data <- y$get()
inverse <- solve(data)
y$cacheInv(inverse)
inverse
}