8000 Update cachematrix.R · cbirole/ProgrammingAssignment2@56b9601 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56b9601

Browse files
authored
Update cachematrix.R
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 '}' }
1 parent b4a6fc7 commit 56b9601

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cachematrix.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ makeCacheMatrix <- function(x = matrix()) {
2727

2828
cacheSolve <- function(x, ...) {
2929
## Return a matrix that is the inverse of 'x'
30-
inv <- x$getinverse{
30+
inv <- x$getinverse{
3131
if(!is.null(inv)){
3232
message('getting cached data')
3333
return (inv)
34-
}
35-
data <- x$get()
36-
inv <- solve(data)
37-
x$setinverse(inv)
38-
inv
39-
}
34+
}
35+
data <- x$get()
36+
inv <- solve(data)
37+
x$setinverse(inv)
38+
inv
39+
}
4040

4141
}

0 commit comments

Comments
 (0)
0