Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cachematrix.R #3

Closed
wants to merge 1 commit into from
Closed

Update cachematrix.R #3

wants to merge 1 commit into from

Conversation

rakesh-k
Copy link

No description provided.

@rakesh-k rakesh-k closed this Apr 17, 2014
gscottwagner added a commit to gscottwagner/ProgrammingAssignment2 that referenced this pull request May 22, 2014
This is good because now I am done with the homework and will enjoy a beer.
KEisenhart added a commit to KEisenhart/ProgrammingAssignment2 that referenced this pull request Jul 17, 2014
odefield added a commit to odefield/ProgrammingAssignment2 that referenced this pull request Aug 21, 2014
A pair of functions that cache the inverse of a matrix:
makeCacheMatrix
cacheSolve

Added more comments to bring clarity to the program

Should be run in the command line/terminal this way:

rdpeng#1. pass a square matrix to makeCacheMatrix (example:
A=matrix(c(1,2,3,4), nrow=2, ncol=2)

rdpeng#2 cache the inverse with cacheSolve(A)

rdpeng#3 access the cached inverse with cacheSolve(A)
christelc added a commit to christelc/ProgrammingAssignment2 that referenced this pull request Oct 25, 2014
MathieuRasa added a commit to MathieuRasa/ProgrammingAssignment2 that referenced this pull request Oct 26, 2014
rafafukai added a commit to rafafukai/ProgrammingAssignment2 that referenced this pull request Nov 23, 2014
ahacme added a commit to ahacme/ProgrammingAssignment2 that referenced this pull request Nov 23, 2014
pursh2002 referenced this pull request in pursh2002/ProgrammingAssignment2 Dec 16, 2014
jnewkirk00 added a commit to jnewkirk00/ProgrammingAssignment2 that referenced this pull request Jan 22, 2015
This is the first draft for programming assignment rdpeng#3.
microprocessorguy added a commit to microprocessorguy/ProgrammingAssignment2 that referenced this pull request Jan 25, 2015
borispetukhov added a commit to borispetukhov/ProgrammingAssignment2 that referenced this pull request Feb 22, 2015
antonf-ekb added a commit to antonf-ekb/ProgrammingAssignment2 that referenced this pull request Feb 22, 2015
gemispence added a commit to gemispence/ProgrammingAssignment2 that referenced this pull request May 23, 2015
squirrelandr added a commit to squirrelandr/ProgrammingAssignment2 that referenced this pull request Jun 21, 2015
russellding referenced this pull request in russellding/ProgrammingAssignment2 Jul 25, 2015
dkutzman added a commit to dkutzman/ProgrammingAssignment2 that referenced this pull request Jul 27, 2015
Edited sample functions to complete assignment rdpeng#3: makeCacheMatrix()
and cacheSolve() defined.
cschooley added a commit to cschooley/ProgrammingAssignment2 that referenced this pull request Aug 20, 2015
dr-projectsinfo added a commit to dr-projectsinfo/ProgrammingAssignment2 that referenced this pull request Sep 22, 2015
013b5b79 pushed a commit to 013b5b79/ProgrammingAssignment2 that referenced this pull request Oct 13, 2015
sharthee pushed a commit to sharthee/ProgrammingAssignment2 that referenced this pull request Oct 23, 2015
squirrelandr added a commit to squirrelandr/ProgrammingAssignment2 that referenced this pull request Oct 23, 2015
dsummersl added a commit to dsummersl/ProgrammingAssignment2 that referenced this pull request Nov 18, 2015
gniapou added a commit to gniapou/ProgrammingAssignment2 that referenced this pull request Jan 23, 2016
Ccappa added a commit to Ccappa/ProgrammingAssignment2 that referenced this pull request Feb 3, 2016
Updates for Programming Assignment rdpeng#3
janekdb added a commit to janekdb/ProgrammingAssignment2 that referenced this pull request Feb 23, 2016
Example test run,

  > testCachingForMatrices(3000)
  [1] "Iteration rdpeng#1 seconds: 18"
  [1] "Iteration rdpeng#2 seconds: 0"
  [1] "Iteration rdpeng#3 seconds: 0"
  [1] "Iteration rdpeng#4 seconds: 0"
amoechsin added a commit to amoechsin/ProgrammingAssignment2 that referenced this pull request Mar 26, 2016
fnets added a commit to fnets/ProgrammingAssignment2 that referenced this pull request Apr 17, 2016
This is my submitted solution to the invert matrix/store matrix in cache
assignment.
izie added a commit to izie/ProgrammingAssignment2 that referenced this pull request Jul 4, 2016
Coursera Assignment rdpeng#3
oattie added a commit to oattie/ProgrammingAssignment2 that referenced this pull request Jul 30, 2016
oattie added a commit to oattie/ProgrammingAssignment2 that referenced this pull request Jul 30, 2016
terrebonne added a commit to terrebonne/ProgrammingAssignment2 that referenced this pull request Aug 9, 2016
…s inverse. #1.  set value of the matrix rdpeng#2.  get value of the matrix rdpeng#3.  set value of the inverse rdpeng#4.  get value of the inversemakeCacheMatrix <- function(x = matrix()) {      j <- NULL     set <- function(y) {       x <<- y       j <<- NULL     }     get <- function() x     setinverse <- function(solve) j <<- solve     getinverse <- function() j     list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)   } ## `cacheSolve` function computes the inverse of the "matrix" returned by `makeCacheMatrix` above.  #If the inverse has already been calculated (and the matrix has not changed), then`cacheSolve` should retrieve the inverse from the cache.  ## when giving: Error in x$getinverse : $ operator is invalid for atomic vectors cachesolve <- function(x, ...) {      i<- x$getinverse()     if(!is.null(j)) {       message("getting cached data")       return(j)     }     data <- x$get()     j<- solve(data, ...)     x$setinverse(j)     j  }


## makeCacheMatrix function creates a "matrix" object that caches its inverse.
#1.  set value of the matrix
rdpeng#2.  get value of the matrix
rdpeng#3.  set value of the inverse
rdpeng#4.  get value of the inversemakeCacheMatrix <- function(x = matrix()) {

    j <- NULL
    set <- function(y) {
      x <<- y
      j <<- NULL
    }
    get <- function() x
    setinverse <- function(solve) j <<- solve
    getinverse <- function() j
    list(set = set, get = get, setinverse = setinverse, getinverse = getinverse)
 
}
## `cacheSolve` function computes the inverse of the "matrix" returned by `makeCacheMatrix` above. 
#If the inverse has already been calculated (and the matrix has not changed), then`cacheSolve` should retrieve the inverse from the cache.

## when giving: Error in x$getinverse : $ operator is invalid for atomic vectors
cachesolve <- function(x, ...) { 
    i<- x$getinverse()
    if(!is.null(j)) {
      message("getting cached data")
      return(j)
    }
    data <- x$get()
    j<- solve(data, ...)
    x$setinverse(j)
    j

}
JohannesCoursera added a commit to JohannesCoursera/ProgrammingAssignment2 that referenced this pull request Jan 1, 2017
DsiturbedAdd pushed a commit to DsiturbedAdd/ProgrammingAssignment2 that referenced this pull request Feb 8, 2017
sideshow31 pushed a commit to sideshow31/ProgrammingAssignment2 that referenced this pull request Apr 4, 2017
Function for assignment rdpeng#3 (programming assignment rdpeng#2)
sideshow31 pushed a commit to sideshow31/ProgrammingAssignment2 that referenced this pull request Apr 4, 2017
Programming in R - Johns Hopkins (Function for assignment rdpeng#3
(programming assignment rdpeng#2)
mksarnala referenced this pull request in mksarnala/ProgrammingAssignment2 May 15, 2017
arsubram added a commit to arsubram/ProgrammingAssignment2 that referenced this pull request May 21, 2017
Test criteria:
1) matrixObj <- makeCacheMatrix(matrix(1:4, 2, 2))
2) matrixObj$getInverse()  ## Returns NULL since matrix has not been solved yet
3) cacheSolve(matrixObj) ## Solves and returns matrix object
4) cacheSolve(matrixObj) rdpeng#3 Retruns matrix object from cache
5) matrixObj <- makeCacheMatrix(matrix(1:9, 3, 3))
6) cacheSolve(matrixObj) ## Returns message: Matrix is singular and cannot be inversed and stops
cbirole added a commit to cbirole/ProgrammingAssignment2 that referenced this pull request Feb 27, 2018
makeCacheMatrix <- function(x = matrix()) {
  inv <- NULL   
  set <- function(y) { rdpeng#2
    x <<- y
    inv <<- NULL
    
  }
  get <- function() x rdpeng#1
  setinverse <- function(inverse) inv <<- inverse rdpeng#3
  getinverse <- function() inv rdpeng#4
  list(set=set, get=get, setinverse=setinverse,getinverse=getinverse)
}

#This function returns the inverse of matrix,
#it checks if the inverse has already been returned first. If so, it gets the result.
#if not, it retrieve the matrix from cache

cacheSolve <- function(x, ...) {
  ## Return a matrix that is the inverse of 'x'
  inv <- x$getinverse{ ##Chitra's comment- Unexpected '{'
    if(!is.null(inv)){
      message('getting cached data')
      return (inv)
    } #Chitra's comment- If I run this code in R - I get an error stating object 'inv' not found
    data <- x$get() #Chitra's comment- $ operator is unexpected here
    inv <- solve(data) #Chitra's comment- R is not able to coerce type 'closure' to vector type 'any'
    x$setinverse(inv) #Chitra's comment- $ is unexpected
    inv #Chitra's comment- Object 'inv' not found
  } #Chitra's comment- unexpected '}'
  
}
@Shakeab21 Shakeab21 mentioned this pull request Oct 21, 2018
megmcginn added a commit to megmcginn/ProgrammingAssignment2 that referenced this pull request Oct 14, 2019
programming assignment - cacheMatrix
JoanCamiloMina added a commit to JoanCamiloMina/ProgrammingAssignment2 that referenced this pull request Aug 27, 2020
Using Cache to store the calculation of the inverse of a matrix, using the concept of a constructive function that generates a list of function to access a set through cache the inverse of the matrix
kenyasmiles referenced this pull request in kenyasmiles/ProgrammingAssignment2 Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant