forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the first draft for programming assignment rdpeng#3.
- Loading branch information
1 parent
7f657dd
commit 5688bcb
Showing
1 changed file
with
27 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
## Put comments here that give an overall description of what your | ||
## functions do | ||
## These functions are designed to cache the inverse of a matrix. This is a demonstration of both | ||
## caching values that take a long time to computer and usage of the <<- operator. | ||
|
||
## Write a short comment describing this function | ||
## makeCacheMatrix creates a special "matrix" object that can cache its inverse | ||
|
||
makeCacheMatrix <- function(x = matrix()) { | ||
|
||
m <- NULL | ||
set <- function(y) { | ||
x <<- y | ||
m <<- NULL | ||
} | ||
get <- function() x | ||
setinv <- function(solve) m <<- solve | ||
getinv <- function() m | ||
list(set = set, get = get, | ||
setinv = setinv, | ||
getinv = getinv) | ||
} | ||
|
||
|
||
## Write a short comment describing this function | ||
## cacheSolve computes the inverse of the special"matrix" returned by makeCacehMatrix. If | ||
## the inverse has already been calculated, and has not changed, the cached result | ||
## is returned | ||
|
||
cacheSolve <- function(x, ...) { | ||
## Return a matrix that is the inverse of 'x' | ||
## Return a matrix that is the inverse of 'x' | ||
m <- x$getinv() | ||
if(!is.null(m)) { | ||
message("getting cached inverse data") | ||
return(m) | ||
} | ||
data <- x$get() | ||
m <- solve(data, ...) | ||
x$setinv(m) | ||
m | ||
} |