Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 84044a2

Browse files
committedFeb 1, 2015
Revert "Revert "R Programming Assignment 2""
This reverts commit 0547a40.
1 parent 0547a40 commit 84044a2

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed
 

‎cachematrix.R

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## functions providing means to cache inverse matrix operations
2+
## Two functions below to be used together to create inverse the matrix objects
33

4-
## Write a short comment describing this function
4+
## creates a special "matrix" object that can cache its inverse
55

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
inv <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
inv <<- NULL
11+
}
12+
13+
get <- function() x
14+
setinv <- function(invmat) inv <<- invmat
15+
getinv <- function() inv
16+
list(set = set, get = get,
17+
setinv = setinv,
18+
getinv = getinv)
819
}
920

1021

11-
## Write a short comment describing this function
22+
## computes the inverse of the special "matrix" returned by makeCacheMatrix
1223

1324
cacheSolve <- function(x, ...) {
1425
## Return a matrix that is the inverse of 'x'
15-
}
26+
inv <- x$getinv()
27+
if(!is.null(inv)) {
28+
message("getting cached data")
29+
return(inv)
30+
}
31+
data <- x$get()
32+
inv <- solve(data, ...)
33+
x$setinv(inv)
34+
inv
35+
36+
}

0 commit comments

Comments
 (0)
Failed to load comments.