File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
1+ # # Code that sets and gets the values of a matrix
2+ # # Then sets and gets the values of the inverse of the matrix
33
4- # # Write a short comment describing this function
5-
6- makeCacheMatrix <- function (x = matrix ()) {
4+ # # This function creates a special matrix which is a list containing functions to get the inverse matrix
75
6+ makeCacheMatrix <- function (x = matrix ()) { # initialize matrix function
7+ mata <- NULL
8+ set <- function (y ) { # set value
9+ x <<- y
10+ mata <<- NULL
11+ }
12+ get <- function () x # get value
13+ setinvmat <- function (inv ) mata <<- inv # set value
14+ getinvmat <- function () mata # get value
15+ list (set = set ,get = get , setinvmat = setinvmat ,getinvmat = getinvmat )
816}
917
1018
11- # # Write a short comment describing this function
19+ # # Function calculates inverse of special matrix: the function checks to see if the inverse was calculated
20+ # # if function has been calculated it returns the inverse from cache and skips calculation.
21+ # # Otherwise the function calculates the inverse of the matrix
1222
1323cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
24+ mata <- x $ getinvmat()
25+ if (! is.null(mata )){
26+ message(" getting cached data" )
27+ return (mata )
28+ }
29+ data <- x $ get()
30+ mata <- solve(data ,... )
31+ x $ setinvmat(mata )
32+ mata
33+ # # Return a matrix that is the inverse of 'x'
1534}
You can’t perform that action at this time.
0 commit comments