Blog of Andrés Aravena
CMB2:

Homework after Class 4

22 February 2017

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:

N <- 60         # simulate 60 steps
y <- rep(NA, N) # create "empty" y vector
y[1] <- 120     # initial position
speed <- -20    # initial speed
for(i in 2:N) { # for each step
  y[i] <- y[i-1] + speed  # update position
  if(y[i] < -180 | y[i] > 180){ # if hit floor OR ceil
    speed <- -speed     # bounce
  }
}
plot(y)

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

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.

Have you seen any of these movies?

What do they have in common?