forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.R
More file actions
41 lines (31 loc) · 700 Bytes
/
Test.R
File metadata and controls
41 lines (31 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mymatrix <- ?matrix(sample(1:100,16),4,4)
solve(mymatrix)
##
makeCacheMatrix <- function(a, b = 1, c = 1) {
x <- matrix(a,b,c)
solved <- NULL
set <- function(y) {
x <<- y
solved <<- NULL
}
get <- function() x
setSolved <- function(inversion) solved <<- inversion
getSolved <- function() solved
list(set = set, get = get,
setSolved = setSolved,
getSolved = getSolved)
}
cacheSolve <- function(x, ...) {
solved <- x$getSolved()
if(!is.null(solved)) {
message("getting cached data")
return(solved)
}
data <- x$get()
solved <- solve(data)
x$setSolved(solved)
solved
}
##
test <- makeCacheMatrix(sample(1:100,16),4,4)
cacheSolve(test)