You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 '}'
}
0 commit comments