Giter Site home page Giter Site logo

programmingassignment2's Introduction

Introduction

I have used exactly the same "schema" provided in the vector mean example in the assignment instructions.

The first function (makeCacheMatrix) defines a wrapper object for a matrix, which I store internally as mat_obj. In practice it defines an "extended" matrix object.

This wrapper contains a second matrix object, which initially is set to NULL and that shall contain the inverse of mat_obj. This I have called mat_inv.

Upon creation of the initial object, mat_inv is set to NULL. It shall be only initialized the first time when a call to cacheSolve is made. Any successive call to cacheSolve shall return the cached object and no longer perform the inverse calculation.

Use of the set function cause a change to mat_obj, therefore also the cached matrix is set to NULL (mat_inv<-NULL), and therefore the next call to cacheSolve() shall have to invert the new mat_obj.

Variables of interest

  • mat_obj: Our input matrix
  • mat_inv: The inverted matrix, initially set to NULL

Internal functions (methods):

  • get: Returns mat_obj
  • set: Sets mat_obj
  • setinverse: Sets mat_inv
  • getinverse Returns the current value of mat_inv (can be NULL)

Usage example

The following makes a "makeCacheMatrix" object called my_threebythree_matrix (printing out the list of methods)

*    my_threebythree_matrix<-makeCacheMatrix(matrix(c(1,2,3,4,5,6,7,8,8),3,3)) 

To get the original matrix:

*    my_threebythree_matrix$get()

This shall output:


       [,1] [,2] [,3]
 [1,]    1    4    7
 [2,]    2    5    8
 [3,]    3    6    8

First time call of cacheSolve:

*    cacheSolve(my_threebythree_matrix)

Shall output:


            [,1]      [,2] [,3]
 [1,] -2.666667  3.333333   -1
 [2,]  2.666667 -4.333333    2
 [3,] -1.000000  2.000000   -1

A second call shall output:


 getting cached data
            [,1]      [,2] [,3]
 [1,] -2.666667  3.333333   -1
 [2,]  2.666667 -4.333333    2
 [3,] -1.000000  2.000000   -1
 

programmingassignment2's People

Contributors

anfe67 avatar rdpeng avatar gustavdelius avatar

Watchers

James Cloos avatar  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.