Skip to content

Commit 76ff369

Browse files
committed
first stab at logic
1 parent c30a386 commit 76ff369

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

cachematrix.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ cachemean <- function(x, ...) {
4343

4444
# makeCacheMatrix: This function creates a special "matrix" object that can cache its inverse.
4545
makeCacheMatrix <- function(x = matrix()){
46-
specialMatrix <- matrix()
47-
46+
specialMatrix <- data.frame("matrix" = x, "inverse" = matrix())
4847

4948
specialMatrix
5049
}
@@ -54,13 +53,12 @@ makeCacheMatrix <- function(x = matrix()){
5453
# If the inverse has already been calculated (and the matrix has not changed),
5554
# then the cachesolve should retrieve the inverse from the cache.
5655
cacheSolve <- function(x, ...){
57-
cache <- matrix()
5856
# Computing the inverse of a square matrix can be done with the solve function in R.
5957
# For example, if X is a square invertible matrix, then solve(X) returns its inverse.
60-
if(!cache$matrixIn){
61-
cache$matrixIn <- solve(matrixIn)
58+
if(!x$inverse){
59+
x$inverse <- solve(x)
6260
}
6361

6462
## Return a matrix that is the inverse of 'x'
65-
cache$matrixIn
63+
x$inverse
6664
}

0 commit comments

Comments
 (0)