Skip to content

Commit

Permalink
Programming Assignement2
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandru1102 committed Apr 24, 2015
1 parent 7f657dd commit ccbefd4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Binary file added .RData
Binary file not shown.
13 changes: 13 additions & 0 deletions .Rhistory
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)
36 changes: 32 additions & 4 deletions cachematrix.R
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
}

0 comments on commit ccbefd4

Please sign in to comment.