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.
- Loading branch information
Showing
1 changed file
with
29 additions
and
12 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,32 @@ | ||
## Put comments here that give an overall description of what your | ||
## functions do | ||
|
||
## Write a short comment describing this function | ||
|
||
# makeCacheMatrix creates a list containing a function to | ||
#1. set the value of the matrix | ||
#2. get the value of the matrix | ||
#3. set the value of inverse of the matrix | ||
#4. get the value of inverse of the matrix | ||
makeCacheMatrix <- function(x = matrix()) { | ||
|
||
inv <- NULL | ||
set <- function(y) { | ||
x <<- y | ||
inv <<- NULL | ||
} | ||
get <- function() x | ||
setinverse <- function(inverse) inv <<- inverse | ||
getinverse <- function() inv | ||
list(set=set, get=get, setinverse=setinverse, getinverse=getinverse) | ||
} | ||
|
||
|
||
## Write a short comment describing this function | ||
|
||
# The following function returns the inverse of the matrix. It first checks if | ||
# the inverse has already been computed. If so, it gets the result and skips the | ||
# computation. If not, it computes the inverse, sets the value in the cache via | ||
# setinverse function. | ||
# This function assumes that the matrix is always invertible. | ||
cacheSolve <- function(x, ...) { | ||
## Return a matrix that is the inverse of 'x' | ||
} | ||
inv <- x$getinverse() | ||
if(!is.null(inv)) { | ||
message("getting cached data.") | ||
return(inv) | ||
} | ||
data <- x$get() | ||
inv <- solve(data) | ||
x$setinverse(inv) | ||
inv | ||
} |
212ce01
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file showing an extra flower braces in line 15 but my actual file didn't have it. here is the original code:
makeCacheMatrix creates a list containing a function to
rdpeng#1. set the value of the matrix
rdpeng#2. get the value of the matrix
rdpeng#3. set the value of inverse of the matrix
rdpeng#4. get the value of inverse of the matrix
makeCacheMatrix <- function(x = matrix()) {
inv <- NULL
set <- function(y) {
x <<- y
inv <<- NULL
}
get <- function() x
setinverse <- function(inverse) inv <<- inverse
getinverse <- function() inv
list(set=set, get=get, setinverse=setinverse, getinverse=getinverse)
}
The following function returns the inverse of the matrix. It first checks if
the inverse has already been computed. If so, it gets the result and skips the
computation. If not, it computes the inverse, sets the value in the cache via
setinverse function.
This function assumes that the matrix is always invertible.
cacheSolve <- function(x, ...) {
}