Skip to content

Commit

Permalink
Updated cachematrix.R for Programming Assignment 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sumlautollner committed Jul 25, 2014
1 parent 7f657dd commit 6c5072b
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions cachematrix.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
## Put comments here that give an overall description of what your
## functions do
## makeCacheMatrix:
## This function creates a special "matrix" object
## that can cache its inverse.
##
## cacheSolve:
## 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 cacheSolve should retrieve the inverse from the cache.

## Write a short comment describing this function

makeCacheMatrix <- function(x = matrix()) {
## Creates a special "matrix" object that can cache its inverse

makeCacheMatrix <- function(x = matrix()) {
inverse <- NULL
set <- function(y) {
x <<- y
inverse <<- NULL
}
get <- function() x
setinverse <- function(solve) inverse <<- solve
getinverse <- function() inverse
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}


## Write a short comment describing this function
## Computes the inverse of the special "matrix" returned by makeCacheMatrix

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


0 comments on commit 6c5072b

Please sign in to comment.