x <- c(0.20, 0.65, 1.13, 2.55, 4.00, 5.75, 7.80, 10.20, 12.90, 16.00, 18.40) y <- c(1.8, 3.6, 5.4, 7.2, 9.0, 10.8, 12.6, 14.4, 16.2, 18.0, 19.8) plot(x, y, type = "o", col = "red", lwd = 3, ylim = c(0,30),xlim = c(0,20),yaxt = "n", xaxt = "n") axis(side = 1, at = 1:20, lwd.ticks = 3,cex.axis = 1.4, font = 2) axis(side = 2, at = c(0,5,10,15,20,25), lwd.ticks = 3, font =2,cex.axis = 1.4) box(which = "plot", lwd = 2) m <- c(-2,11) n <- c(15,15) lines(n~m) a <- c(11,11) b <- c(-1.2,15) lines(b~a, lty = 2) fit <- lm(y~x) fit abline(fit, lty = 2, lwd = 2, col = "purple") fit <- nls(y~a*x^b, start = list(a = 2, b = 1.5)) fit
托马斯微积分 p28
x <- c(20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80) y <- c(42, 56, 73.5, 91.5, 116, 142.5, 173, 209.5, 248, 292.5, 343, 401, 464) fit <- lm(y~x + I(x^2)) fit plot(x, y, pch = 16, lwd.ticks = 3, xlim = c(20,90),cex.axis = 1.4, cex.lab = 1.4) lines(x, y, col = "red", lwd = 3) box(which = "plot", lwd = 3) lines(x, fitted(fit)) 0.08859 * 85^2 - 1.97013 * 85 + 50.05944 abline(v = 72, lwd = 3) abline(v = 85, lwd = 3) fit2 <- lm(y~x) fit2 abline(fit2, lwd = 3, col = "purple") 6.889 * 85 - 140.412