From 136c90b5ac8077cd8951c1cd7babc7c8972d50bd Mon Sep 17 00:00:00 2001 From: bessxu Date: Tue, 22 Apr 2014 09:30:01 +0800 Subject: [PATCH 1/2] peer assessment --- cachematrix.R | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..64dc853e540 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,30 @@ -## Put comments here that give an overall description of what your -## functions do +#makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse. -## Write a short comment describing this function makeCacheMatrix <- function(x = matrix()) { - + inverse<-NULL + set<-function(y){ + x<<-y + inverse<-NULL + } + get<-function()x + + setinverse<-function(inverse)inverse<<-solve(x) + + getinverse<-function()inverse + list(set=set, get=get,setinverse=setinverse, getinverse=getinverse) } - -## Write a short comment describing this function +#cacheSolve: 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' + inverse<-x$getinverse() + if(!is.null(inverse)){ + message("getting cached data") + return(inverse) + } + data<-as.matrix(x$get()) + inverse<-solve(data) + x$setinverse(inverse) + inverse } From f402ef6e2c44be34a5d0622e2bc5cd6f321b2f02 Mon Sep 17 00:00:00 2001 From: bessxu Date: Tue, 22 Apr 2014 09:35:03 +0800 Subject: [PATCH 2/2] peer assessment --- ProgrammingAssignment2 | 1 + 1 file changed, 1 insertion(+) create mode 160000 ProgrammingAssignment2 diff --git a/ProgrammingAssignment2 b/ProgrammingAssignment2 new file mode 160000 index 00000000000..e4eed4153bd --- /dev/null +++ b/ProgrammingAssignment2 @@ -0,0 +1 @@ +Subproject commit e4eed4153bd237a2dd4532fc3f40ce0e22fd0cb7