Skip to content

Commit 6ee8fef

Browse files
committed
Committing cachematrix.r
Using github for the first time.
1 parent 9b22d21 commit 6ee8fef

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

.Rhistory

Whitespace-only changes.

cachematrix.R

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,36 @@
44
## Write a short comment describing this function
55

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

1021

1122
## Write a short comment describing this function
1223

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

0 commit comments

Comments
 (0)