10000 Assignment 3 · izie/ProgrammingAssignment2@a39ea70 · GitHub
[go: up one dir, main page]

Skip to content

Commit a39ea70

Browse files
committed
Assignment 3
Coursera Assignment rdpeng#3
1 parent 7f657dd commit a39ea70

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cachematrix.R

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

66
makeCacheMatrix <- function(x = matrix()) {
7-
7+
m <- NULL
8+
set <- function(y) {
9+
x <<- y
10+
m <<- NULL
11+
}
12+
get <- function() x
13+
setinverse <- function(inv) i <<- inv
14+
getinverse <- function() i
15+
list(set = set, get = get,
16+
setinverse = setinverse,
17+
getinverse = getinverse)
818
}
919

1020

1121
## Write a short comment describing this function
1222

1323
cacheSolve <- function(x, ...) {
1424
## Return a matrix that is the inverse of 'x'
25+
i <- x$getinverse()
26+
if(!is.null(i)) {
27+
message("getting cached data")
28+
return(i)
29+
}
30+
data <- x$get()
31+
i <- mean(data, ...)
32+
x$setinverse(i)
33+
i
1534
}

0 commit comments

Comments
 (0)
0