Skip to content

Update cachematrix.R #5815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
59 changes: 48 additions & 11 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
## Put comments here that give an overall description of what your
## functions do

## Write a short comment describing this function

makeCacheMatrix <- function(x = matrix()) {

# Creates a special matrix object that can cache its inverse
# Argument parameter: Matrix, Output: List
makeCacheMatrix <- function(x = matrix()){
# Initialize the inverse value
m <- NULL

# Method to set the matrix
set <- function(y){
x <<- y
m <<- NULL
}

# Method to get the matrix
get <- function() x

# Method to set the inverse of the matrix
setinverse <- function(inverse) m <<- inverse

# Method to get the inverse of the matrix
getinverse <- function() m

# Output list
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}


## Write a short comment describing this function

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
# To compute the inverse of the special matrix
# Argument parameter: Matrix, Output: Inverse Matrix
cacheSolve <- function(x, ...){
# Initialize a matrix that is the inverse of x matrix
m <- x$getinverse()

# Return a matrix if it is the inverse of x matrix
if(!is.null(m)) {
message("getting cached data")
return(m)
}

# Get the matrix from the object
data <- x$get()

# Method to solve the inverse using matrix multiplication
m <- solve(data, ...)

# Set the inverse of inverse matrix
x$setinverse(m)

# Return the matrix
m
}