-
Notifications
You must be signed in to change notification settings - Fork 144k
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
1 parent
7f657dd
commit ccbefd4
Showing
3 changed files
with
45 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
setwd("C:/Users/Chandru/ProgrammingAssignment2") | ||
source("cachematrix.R"") | ||
"" | ||
source("cachematrix.R") | ||
mat <- matrix(rnorm(1:(16)), nrow=4, ncol=4) | ||
a <- makeCacheMatrix(mat) | ||
cacheSolve(a) | ||
cacheSolve(a) | ||
source("cachematrix.R") | ||
mat <- matrix(rnorm(1:(16)), nrow=4, ncol=4) | ||
a <- makeCacheMatrix(mat) | ||
cacheSolve(a) | ||
cacheSolve(a) |
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,43 @@ | ||
## Put comments here that give an overall description of what your | ||
## functions do | ||
## The following functions speed up to compute repeated matrix inversion | ||
## for a single matrix using caching technique | ||
|
||
## Write a short comment describing this function | ||
|
||
## This function creates a special "matrix" object that can cache its inverse. | ||
|
||
makeCacheMatrix <- function(x = matrix()) { | ||
im <- NULL ## im for inversion matrix | ||
|
||
set <- function(y) { ## set the matrix | ||
x <<- y | ||
im <<- NULL | ||
} | ||
get <- function() x ## get the matrix | ||
setinv <- function(solve) im <<- solve ## set inversion matrix | ||
getinv <- function() im ## get inversion matrix | ||
|
||
list(set = set, ## store the functions | ||
get = get, | ||
setinv = setinv, | ||
getinv = getinv) | ||
|
||
} | ||
|
||
|
||
## Write a short comment describing this function | ||
## 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 the cachesolve should retrieve the inverse from the cache. | ||
|
||
cacheSolve <- function(x, ...) { | ||
## Return a matrix that is the inverse of 'x' | ||
|
||
im <- x$getinv() ## get inversion from cache | ||
|
||
if(!is.null(im)){ ## check if it is not NULL | ||
message("getting cached data") | ||
return(im) ## return the cache data and save some computation | ||
} | ||
data <- x$get() ## if we are here we need compute | ||
im <- solve(data, ...) ## compute the inverse | ||
x$setinv(im) ## save it to cache | ||
im ## return the computed inverse matrix | ||
} |