Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
## Put comments here that give an overall description of what your
## functions do
## Rajeev Agrawal
## This function is gonna create a set of setter and getter
## Functions.
## This will save the inverse of a matrix in cache
makeCacheMatrix <- function(m = matrix(NA,2,2)){

## Write a short comment describing this function
# Assigned NA value to r, which is reverse of matrix
r <<- matrix(NA,2,2)

makeCacheMatrix <- function(x = matrix()) {
# Set function will reset the value of m and r
set <- function(y){
m <<- y
r <<- matrix(NA,2,2)
}

}
# Get function will pull the value of m, which is input
get <- function() m

# This function will push the reverse of m to r
setrev <- function(solv) r <<- solv

## Write a short comment describing this function
# This function will get the value of r
getrev <- function() r
list(set = set, get = get,
setrev = setrev,
getrev = getrev)
}

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
# This function calls
cacheSolve <- function(m,...){
# Assignin cached value of r
r <- m$getrev()
if(!all(is.na(r))) {
message("getting cached data")
return(r)
}
# Extracting value of input mtrix m
data <- m$get()
# Calculating the reverse of m
r <- solve(data, ...)
# Setting the reverse of m to r in makeCacheMatrix
m$setrev(r)
r
}