For this homework you have to prepare a Rmarkdown document. The homework has a mandatory part and two optional ones.
You can download the Rmarkdown file used in the class and the HTML page produced from it.
Simulate Gravity
The last simulation we did in Class 4 was this:
<- 60 # simulate 60 steps
N <- rep(NA, N) # create "empty" y vector
y 1] <- 120 # initial position
y[<- -20 # initial speed
speed for(i in 2:N) { # for each step
<- y[i-1] + speed # update position
y[i] if(y[i] < -180 | y[i] > 180){ # if hit floor OR ceil
<- -speed # bounce
speed
}
}plot(y)
- Modify this code to simulate gravity. Initial
speed
should be 0 and it must change by -1 on every step - We want to make a plot to see how the speed changes. Make another
version that saves the speed for each step. Now
speed
must be a vector. You have to insert the correct indices. It is similar toy
.
You must send me one file in Rmd
format
with two pieces of code and two graphics.
Exercise (optional)
This is optional, but recommended to understand better. On Class 5 we will explore how things move when they are connected to an elastic rubber band.
{: .sidenote}
To be prepared, please read about
- Hooke’s law for springs
- Kinetic and Potential Energy
Good to know (optional)
When we use Scratch we can see a “movie” that is more fun than the graphics on R. Sometimes a movie can be a better way to explain an idea.
- Explore how can we animate graphics in R. Tell me something I don’t know.
Have you seen any of these movies?
- Gravity
- Apollo 13
- The Martian
What do they have in common?