-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
41 lines (36 loc) · 843 Bytes
/
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
## Put comments here that give an overall description of what your
## functions do
## This function make a cache matrix
##
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
minv <- NULL
set <- function(y) {
x <<- y
m <<- NULL
minv <<- NULL
}
get <- function() x
setmean <- function(mean) m <<- mean
getmean <- function() m
setminv <- function(solve) minv <<- solve
getminv <- function() minv
list(set = set,
get = get,
setmean = setmean,
getmean = getmean,
setminv = setminv,
getminv = getminv)
}
## This function calculate the inverse of a matrix
cacheSolve <- function(x, ...) {
minv <- x$getminv()
if(!is.null(minv)) {
message("getting cached data")
return(minv)
}
dataMatrix <- x$get()
minv <- solve(dataMatrix, ...)
x$setminv(minv)
minv
}