Skip to content

ProgrammingAssignment2_Inverse Matrix #2246

@Dashyta88

Description

@Dashyta88

makeCachMatrix creates a special "matrix"

object that can cache its inverse:

1. set the value of the matrix

2. get the value of the matrix

3. set the value of the solve (inverse)

4. get the value of the solve (inverse)

we are assuming that the matrix supplied is always invertible

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

set <- function(y)
{
x <<- y
m_inv <<- NULL
}

get <- function() x
setm_inv <- function(solve) m_inv <<- solve

getm_inv <- function() m_inv

list(set = set, get = get,
setm_inv = setm_inv,
getm_inv = getm_inv)
}

This function computes the inverse of the special "matrix"

returned by makeCacheMatrix above. If the inverse has already

been calculated (and the matrix has not changed),

then the cachesolve should retrieve the inverse from the cache.

cacheSolve <- function(x, ...) {
m_inv <- x$getm_inv()
if(!is.null(m_inv)) {
message("getting cached data")
return(m_inv)
}
data <- x$get()
m_inv <- solve(data, ...)
x$setm_inv(m_inv)
m_inv
}

Activity

terrebonne

terrebonne commented on Aug 15, 2016

@terrebonne

Thank you for the comment.
Indeed i"m aware of these actions but they had seemed obvious.

Thank you again to remind me

2016-08-13 17:38 GMT-04:00 Dashyta88 notifications@github.com:

makeCachMatrix creates a special "matrix" object that can cache its
inverse: 1. set the value of the matrix 2. get the value of the matrix 3.
set the value of the solve (inverse) 4. get the value of the solve
(inverse) we are assuming that the matrix supplied is always invertible

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

set <- function(y)
{
x <<- y
m_inv <<- NULL
}

get <- function() x
setm_inv <- function(solve) m_inv <<- solve

getm_inv <- function() m_inv

list(set = set, get = get,
setm_inv = setm_inv,
getm_inv = getm_inv)
}
This function computes the inverse of the special "matrix" returned by
makeCacheMatrix above. If the inverse has already been calculated (and
the matrix has not changed), then the cachesolve should retrieve the
inverse from the cache.

cacheSolve <- function(x, ...) {
m_inv <- x$getm_inv()
if(!is.null(m_inv)) {
message("getting cached data")
return(m_inv)
}
data <- x$get()
m_inv <- solve(data, ...)
x$setm_inv(m_inv)
m_inv
}


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#2246, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AT8eZs82fxyvtvPAp58e6qr51kWhEn7sks5qfjldgaJpZM4Jjw-b
.

P.-André Dupuis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @terrebonne@Dashyta88

        Issue actions

          ProgrammingAssignment2_Inverse Matrix · Issue #2246 · rdpeng/ProgrammingAssignment2