Git Product home page Git Product logo

programmingassignment2's Introduction

Assignment: Caching the Inverse of a Matrix

"The operater '<<-' opertor is used a value to an object in an environment that is different from the current environment. Below are two functions that are used to create a special object that stores a numeric matrix and caches its inverse. The inverse of matrix can be calculated 'solve' function in R package.

'makeCacheMatrix' function creates a special object that stores a numeric matrix,

which is really a list containing a function:

  1. set: set the value of the matrix
  2. get: get the value of the matrix
  3. setInverse: set the value of the inverse of matrix
  4. getInverse: get the value of the inverse of matrix.
"

makeCacheMatrix <- function(x = matrix()) { m <- NULL set <- function(y) { x <<- y m <<- NULL } get <- function() x setInverse <- function(solve) m <<- solve
getInverse <- function() m list(set = set, get = get, setInverse = setInverse, getInverse= getInverse) }

'CacheSolve' function do the following jobs:

" - calculates the inverse of the special 'matrix' created with the above function.

  • checks to see first if the inverse of matrix is already calculated.
  • if the inverse of matrix is already calculated, it gets inverse of matrix from cache and skips the computation. -if not, calculates the inverse of matrix of the data and sets the value of the inverse of matrix in the cache via the setInverse function."

cacheSolve <- function(x, ...) {

m <- x$getInverse()
if(!is.null(m)) {
    message("getting cached data")
    return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setInverse(m)
m

}

programmingassignment2's People

Contributors

rdpeng avatar raylight10 avatar gustavdelius avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.