Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rdpeng/ProgrammingAssignment2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: solt87/ProgrammingAssignment2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 4 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 26, 2016

  1. First working solution.

    solt87 committed Mar 26, 2016
    Copy the full SHA
    288d939 View commit details
  2. Copy the full SHA
    7299ca3 View commit details
  3. Copy the full SHA
    318ab97 View commit details
  4. Typo, whitespace.

    solt87 committed Mar 26, 2016
    Copy the full SHA
    dc68a3d View commit details
Showing with 40 additions and 6 deletions.
  1. +40 −6 cachematrix.R
46 changes: 40 additions & 6 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
## Put comments here that give an overall description of what your
## functions do
## makeCacheMatrix() creates a special "matrix" object that
## can cache its inverse.
## cacheSolve() returns the inverse of such a special "matrix".

## Write a short comment describing this function

## Creates a "matrix" that can cache its own inverse.
## Returns a list containing functions to view or edit the matrix and its
## inverse.
makeCacheMatrix <- function(x = matrix()) {

## Inverse not yet computed
inv <- NULL
## The setter function of the matrix
set <- function( y ) {
x <<- y
## The matrix just got a new value, so
## the inverse is not yet known
inv <<- NULL
}
## The getter function of the matrix
get <- function() x
## The setter function of the inverse of the matrix
setinv <- function( invv ) inv <<- invv
## The getter function of the inverse of the matrix
getinv <- function() inv
## Return the list that makes the matrix functions accessible
list( set = set, get = get,
setinv = setinv,
getinv = getinv )
}


## Write a short comment describing this function

## Returns the inverse of the special matrix 'x', either from
## cache (if available), or by computing it.
## ASSUME that the matrix supplied is always invertible.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'

## Get the stored inverse (if any) from 'x'
inv <- x$getinv()
## If the inverse is cached, return cached value
if ( !is.null(inv) ) {
message("Getting cached data...")
return( inv )
} ## Else get the data...
data <- x$get()
inv <- solve( data, ... ) ## ... compute its inverse ...
x$setinv( inv ) ## ... set the inverse in x's cache, and...
inv ## ... return the computed inverse.
}