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
38 lines (34 loc) · 1.13 KB
/
cachematrix.R
File metadata and controls
38 lines (34 loc) · 1.13 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
## Put comments here that give an overall description of what your
## functions do
# Function to return a set of lists that can be used later to inverse a matrix...
# and determine whether it already has a value.
# @param: matrix
# @return: list containing four functions with the same given name
makeCacheMatrix <- function(x = matrix()) {
mat <- NULL
set <- function(y) {
x <<- y
m <<- NULL
}
get <- function() x
setmatrix <- function(matrix) mat <<- matrix
getmatrix <- function() mat
list(set = set, get = get,
setmatrix = setmatrix,
getmatrix = getmatrix)
}
# This function takes the argument from previous function and checks its value
# @param: x as a matrix created in a previous function
# @return: the inverse of special matrix x named mat
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
mat <- x$getmatrix()
if (!is.null(mat)) { ## checks whether the value is present or not
message("Setting inverse matrix")
return (mat)
data <- x$get()
mat <- solve(data) ## inverse the matrix using function solve()
x$setmatrix(mat)
return (mat)
}
}