From ccbefd4df5b125f4b2d3e81a72e9b330d84e3f82 Mon Sep 17 00:00:00 2001 From: Chandru Date: Fri, 24 Apr 2015 15:51:07 -0500 Subject: [PATCH] Programming Assignement2 --- .RData | Bin 0 -> 7452 bytes .Rhistory | 13 +++++++++++++ cachematrix.R | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 .RData create mode 100644 .Rhistory diff --git a/.RData b/.RData new file mode 100644 index 0000000000000000000000000000000000000000..180aeffd09f1cc3d649f6ca30834d5f3ab1f93f0 GIT binary patch literal 7452 zcmV+%9pmC3iwFP!000002JKu2SX0Rsz5%57-VIGc5wIgt6hy^EL_h@#5+Fd3W)cLu zt5{Z1kyRJligjJfTGvXktzyBhYZtL$TN`$icW*L7PHt`xaoxA?`ySsn{x|2JbLPyM zdXpI=x<|LwjMgLwLWxjjDHBS{*r#!z{p#aV6dwFkXN52(AGbY@fW zy~*?b@H12iUAwCAPxWNw5SP;Q)P(jmzi<|HNzAxAb#bo=r{^iD>io5_py$QS?GoQC zJF_C@_leo&(XsDJcmBHJlE>iD1#MHS9@T3vPwm_{+4w+<-a`vYKE1kJ=;j(Rt8i2C z5!1w1zd0LDRDU^syH?kJryrOfJhf|kA}48JRSfHZx95*H78VC~FuGrRYuc7KcV=ck z`4GM%@3+K?b$cvLO*&3@-PB?ovBTr?&sF0GD>)o|_N3b!_03*x8#Kdw3Vz$&A!pF> z>ehQlzx3A}yRuVk`GVeR^P_BTZs@<=X3~6rhoNl>{u=l;Z=?S`eVg1kpV@=WpYeCE z{Ar20$E`IxlD1|)4_vP8@XHhxfuMH4p|zd8rq%ysJhZd>pr|sFg3-GUzx<h34oyUcbTsSz6{=yhQ2``WJShdt9c+G5Wimtuz0PW?6XGS~Lb*q5)q zQ;zqv);aHTY5JescULOIUZy7Q8dKc6pa}lG`c8jU(c~glWUhMEsse& zR4`S!Z^n205DS$I#v#h6cokPO7xWgAk zSALs5D5~}5)m_H7Enj?$-$U!l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i~@5ysUbZt@E>bfT5hwf?hGh@6FByl+?wwLE_zJ;ldE+wpzdYd+`)To%OCu* zL~Yda@PNC4B>{KUivr%=c3=L!d|vsvw>hA$f8#S4DsX+3+rG>0R~zF1s`2LMi+GYadZpt*`e9ZOF!goL`V;fJ2u-Y z{b;ojAw8Z+np29+%(nV;`~z zx~chEJiYNn~HS@X3T8 zeXY}wv(a@A-<-qf20p7bdr(jbKbxXwQz_R>tMvZ`0Hu(4s{6W?hxMz(kGg+J8ZCONXXv4)In${k$rt3@)0i43* zrT_&~geB9oC;jb3%+cRJKf7f8{~ffk_WswsgHoTr-8Y9!z0MqX?hZWyHTZUK!%QBT zFnA>Q{;D9BrXbee?v0wsYokWuXiSfzKJhodO*3wGBu4_o7O1(!5?P~K+#Eequ{J@^ aR1M%po08eq|BrlS_vt^nuZ#8xV*mgE&I)$` literal 0 HcmV?d00001 diff --git a/.Rhistory b/.Rhistory new file mode 100644 index 00000000000..525d439f9a6 --- /dev/null +++ b/.Rhistory @@ -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) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..01365e7627c 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -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 }