# Construct a D-optimal design for SLR on [0,1] k0 = 5 k.end = 1000 par(mfrow = c(2,1)) x0 = seq(from = 0, to = 1, length = k0) # Five-point intial design hist(x0, breaks = 100, freq = F) x = x0 for (k in k0:(k.end-1)) { M = cbind(c(1, mean(x)), c(mean(x), mean(x^2))) # Form M(xi_k) Minv = solve(M) # and its inverse q = function(t) -sum(c(1,t)*(Minv%*%c(1,t))) # The minimizer of q(t) is the next design point newx= nlminb(start = .5, objective = q, lower = 0,upper = 1)$par cat("k = ", k, "newx = ", newx, "\n") x = c(x,newx) } x hist(x, breaks = 100, freq = F)