Skip to content

Commit c9b424f

Browse files
committed
Added first pass code
Added comments and first pass at code
1 parent 7f657dd commit c9b424f

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

cachematrix.R

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
51

2+
## Function makeCacheMatrix
3+
##
4+
## Purpose:
5+
## Create a special "matrix" object that can cache its inverse.
6+
##
7+
## On Entry:
8+
## x - matrix
9+
##
10+
## One Exit:
11+
## returns an object that sotres a numeric vector and caches it inverse
12+
##
13+
##
614
makeCacheMatrix <- function(x = matrix()) {
7-
15+
m <- NULL
16+
set <- function(y) {
17+
x <<- y
18+
m <<- NULL
19+
}
20+
get <- function() x
21+
setinverse <- function(inverse) m <<- inverse
22+
getinverse <- function() m
23+
list(set = set, get = get,
24+
setinverse = setinverse,
25+
getinverse = getinverse)
26+
827
}
928

10-
11-
## Write a short comment describing this function
12-
29+
## Function cacheSolve
30+
##
31+
## Purpose:
32+
## Computes the inverse of the special "matrix" returned by makeCacheMatrix.
33+
## If the inverse has already been calculated (and the matrix has not changed), then the cachesolve
34+
## should retrieve the inverse from the cache.
35+
##
36+
## On Entry:
37+
## Params: x matrix
38+
## '...' to pass through to solve
39+
## On Exit:
40+
## Returns a matrix that is the inverse of 'x'
41+
##
1342
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
43+
m <- x$getinverse()
44+
if(!is.null(m)) {
45+
message("getting cached data")
46+
return(m)
47+
}
48+
data <- x$get()
49+
m <- inverse(data, ...)
50+
x$setinverse(m)
51+
m
1552
}

0 commit comments

Comments
 (0)