File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ ide <- mat %*% inv
8
8
9
9
# Generate a random 2 x 2 matrix of integers from 1 to 10
10
10
di <- 2
11
- mat <- matrix (sample(1 : 10 , di * di ), di , di )
11
+ mat <- matrix (sample(1 : 10 , di ^ 2 ), di , di )
12
12
# Invert matrix
13
13
inv <- solve(mat )
14
14
# General identity matrix
@@ -24,3 +24,21 @@ cs <- cacheSolve(cm)
24
24
is.null(cm $ gets())
25
25
26
26
identical(inv , cacheSolve(cm ))
27
+
28
+ # Test using large matrix so caching is evident
29
+ lm <- matrix (runif(di ^ 2 ), di )
30
+ cm <- makeCacheMatrix(lm )
31
+ # Should take some time
32
+ system.time(cs <- cacheSolve(cm ))
33
+ # Should be much faster
34
+ system.time(cs <- cacheSolve(cm ))
35
+ identical(solve(lm ), cs )
36
+
37
+ # Should produce proper identity matrix
38
+ round(lm %*% cs , 4 )
39
+
40
+ # Confirm
41
+
42
+ system.time(t1 <- cacheSolve(test ))
43
+
44
+ system.time(t1 <- cacheSolve(test ))
You can’t perform that action at this time.
0 commit comments