diff --git a/ch10.r b/ch10.r index 365ffea..16e0fa9 100644 --- a/ch10.r +++ b/ch10.r @@ -28,3 +28,35 @@ for (i in 1:20) { matplot(t, x, lwd=2, col="gray") grid() lines(t, 0*cos(2*pi*t), lwd=4, col="darkred") + +## Example 10.8 + +# R code for Example 10.7 +x = matrix(0, 21, 20) +t = 0:20 + +for (i in 1:20) { + x[,i] = runif(1) ^ t +} + +stem <- function(x,y,pch=1,...){ + if (missing(y)){ + y = x + x = 1:length(x) + } + for (i in 1:length(x)){ + lines(c(x[i],x[i]), c(0,y[i]), ...) + } + lines(c(x[1]-2,x[length(x)]+2), c(0,0), ...) +} + +matplot(t, x, pch=1, col="gray", lwd=2) +grid() + +for (i in 1:ncol(x)) { + stem(t, x[,i], col="gray", lwd=2) +} +stem(t, 1/(t+1), col="darkred", lwd=2, pch=1, type="o") + + +