Skip to content

Instantly share code, notes, and snippets.

@sumanthratna
Last active February 8, 2020 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumanthratna/58dce4e04feaef702000e8e87caaf6ff to your computer and use it in GitHub Desktop.
Save sumanthratna/58dce4e04feaef702000e8e87caaf6ff to your computer and use it in GitHub Desktop.
R code for generating the graph for the Trip Lab in AP Calculus AB.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
library("ggplot2")
library("ggalt")
odo <- data.frame(time = seq(0, 600, 15), speed = c(0, 5.866666667, 5.866666667, 11.73333333, 33.73333333, 30.8, 33.73333333, 7.333333333, 45.46666667, 48.4, 45.46666667, 30.8, 32.26666667, 55.73333333, 55.73333333, 0, 0, 48.4, 58.66666667, 45.46666667, 45.46666667, 16.13333333, 33.73333333, 74.8, 73.33333333, 70.4, 60.13333333, 45.46666667, 48.4, 57.2, 55.73333333, 49.86666667, 46.93333333, 30.8, 35.2, 33.73333333, 30.8, 35.2, 30.8, 30.8, 27.86666667))
ggplot(odo, aes(odo$time, odo$speed)) + geom_point(aes(x = time, y = speed), stat = "identity") + ggtitle("Speed of a Car Over a 10 Minute Interval") + xlab("Time (s)") + ylab("Speed (ft/s)") + geom_smooth() + geom_xspline() + scale_x_continuous(breaks = round(seq(min(odo$time), max(odo$time), by = 30), 1)) + scale_y_continuous(breaks = round(seq(min(odo$speed), max(odo$speed), by = 5), 1))
lhs = 30*sum(odo$speed[seq(1, 40, 2)])
rhs = 30*sum(odo$speed[seq(3, 41, 2)])
midpoint = 30*sum(odo$speed[seq(2, 40, 2)])
trap = 30*sum(rowMeans(embed(odo$speed[c(TRUE, FALSE)], 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment