diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..5b6a0652566 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/ProgrammingAssignment2.Rproj b/ProgrammingAssignment2.Rproj new file mode 100644 index 00000000000..8e3c2ebc99e --- /dev/null +++ b/ProgrammingAssignment2.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..33dd910c291 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,25 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - -makeCacheMatrix <- function(x = matrix()) { - +makeMatrix <- function(x = matrix()) { + i<-NULL + set<-function(y){ + x<<-y + i<<-NULL + } + get<-function() x + setmat<-function(solve) i<<- solve + getmat<-function() i + list(set=set, get=get, + setmat=setmat, + getmat=getmat) } - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' +cacheSolve <- function(x=matrix(), ...) { + i<-x$getmat() + if(!is.null(i)){ + message("getting cached data") + return(i) + } + matrix<-x$get() + i<-solve(matrix, ...) + x$setmat(i) + i }