Purpose : To approximate the non negative random variable with a set of simple functions

> par(new = F)
> par(mfrow = c(1, 1))
> x <- sort(runif(1000, 0, 4), decreasing = F)
> ylim <- c(0, 5)
> xlim <- range(x)
> cols <- rainbow(5)
> leg.label <- paste("n", 1:5, sep = " = ")
> temp <- expression(paste(psi[n] == min, "( ", n, " , ", 2^{
+     -n
+ } * floor(x * 2^{
+     n
+ }), " ) "))
> for (n in 1:5) {
+     y <- pmin(n, 2^(-n) * floor(2^(n) * x))
+     plot(x, y, type = "l", lwd = 3, xlim = xlim, ylim = ylim,
+         col = cols[n], xlab = "x", ylab = "y")
+     par(new = T)
+ }
> plot(y, y, xlim = xlim, ylim = ylim, col = "sienna", lwd = 2,
+     xlab = "x", ylab = "y", main = " Approximate Non negative function with Simple Functions")
> legend("topleft", legend = leg.label, fill = cols)
> legend("topright", legend = temp)

Chapter4-001.jpg

I am coding a graphic after what seems like ages. Well, the main reason is the lack of peaceful mind space. I thank god for giving me back this silence and solitude where I can understand stuff properly