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: akarray/ProgrammingAssignment2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Aug 23, 2014

  1. cachematrix.R

    akarray committed Aug 23, 2014
    Copy the full SHA
    abfdd2c View commit details
Showing with 41 additions and 7 deletions.
  1. +41 −7 cachematrix.R
48 changes: 41 additions & 7 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
## The goal of this pair of functions is to cache the inverse of a matrix.

## Write a short comment describing this function

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

## makeVector creates a special "matrix", which is really a matrix containing a function to
## set the value of the squared matrix
## get the value of the squared matrix
## set the value of the inverse of the matrix
## get the value of the inverse of the matrix

makeCacheMatrix <- function(m = matrix()) {
inv <- NULL
set <- function(y) {
m <<- y
inv <<- NULL
}
get <- function() m
setinverse <- function(inverse) inv <<- inverse
getinverse <- function() inv

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


## Write a short comment describing this function
## cacheSolve function calculates the inverse of the matrix created with the makeCacheMatrix function.
## However, it first checks to see if the inverse of the matrix has already been calculated.
## If so, it gets the inverse of the matrix from the cache and skips the computation.
## Otherwise, it calculates the inverse of the matrix and sets the value of the inverse in the cache via the setinverse function.

cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
cacheSolve <- function(m) {
## Return a matrix that is the inverse of 'm'
inv <- m$getinverse()
if(!is.null(inv)) {
message("getting cached data")
return(inv)
}
data <- m$get()
inv <- solve(data)
m$setinverse(inv)
inv

}


## This code is used just for test purpose
## m <- makeCacheMatrix(matrix(1:4,2,2))
## t <- cacheSolve(m)