slope <- function(x,y) sum(x*y) / sum(x^2) x <- c(1:10) m0 <- 3; y <- m0 * x x y m0 <- 3; y <- m0 * x + rnorm(10, 0, 0.5) y plot(x,y) plot(x,y, xlim=c(0, 10), ylim=c(0, 35) ) grid() m <- slope(x,y) m abline(0,m) t <- seq(0, 10, by=0.1) t v0 <- 20 # m/s th <- 45 * pi/180 ; x0x <- v0 *cos(th) ; v0y <- v0*sin(th) th th <- 45 * pi/180 ; v0x <- v0 *cos(th) ; v0y <- v0*sin(th) v0x v0y x <- v0x * t ; y <- v0y * t + 1/2 * (-g)*t^2 g <- 9.8 # m/s^2 x <- v0x * t ; y <- v0y * t + 1/2 * (-g)*t^2 plot(x,y, asp=1) plot(x,y, asp=1, col='blue', cex=0.5) grid() th <- 20 * pi/180 ; v0x <- v0 *cos(th) ; v0y <- v0*sin(th) x <- v0x * t ; y <- v0y * t + 1/2 * (-g)*t^2 points(x,y, col='blue', cex=0.5) th <- 80 * pi/180 ; v0x <- v0 *cos(th) ; v0y <- v0*sin(th) x <- v0x * t ; y <- v0y * t + 1/2 * (-g)*t^2 points(x,y, col='blue', cex=0.5) max(t) q()