Lab 7

From CSE100B Wiki

Jump to: navigation, search

Before you begin lab 7, check out the course project specifications if you haven't done so.

Animation with Forces: Part A

In this lab, you will modify your hockey table to support multiple pucks and forces (gravity, pucks that repel each other).

lab7_1.m:

In this lab, we do not consider gravity yet. Using your code from the last lab (lab6_4.m) as a starting point, add another puck to the hockey table. The position of each puck should be stored in a matrix where each row corresponds to one puck. The velocity of each puck should be stored in a matrix where each row corresponds to one puck. Your code should have this structure:

initialize position matrix
initialize velocity matrix
plot the initial positions of the pucks and store the handle
...
start loop
    update the positions
    for idx = 1:n
        check the position and velocity of puck "idx"
    end
    update the plot using the handle
    ...
end loop

Physics tells us that velocity measures the change in position of an object per time unit and acceleration measures the change in velocity per time unit. Assume that, on the hockey table, gravity will cause a constant acceleration in the -y direction. If we start the puck with no velocity at the top of the table, the puck will gain velocity as it falls to the bottom.

lab7_2.m:

Add gravity as a negative constant acceleration in the y direction to your hockey table with two pucks. The three things you need to do are:

  1. Create a new matrix for the acceleration.
  2. Modify the current update function to update both the position and the velocity as a function of time. You might want to save a copy of the old function around so you can still use it for lab7_1.m.
  3. You will need to pass the acceleration to the new update function along with other parameters.

(You should not have to modify your boundary checking function.)

Q1: How does changing the time step affect your simulation?

Demonstrate Q1 and lab7_1.m, lab7_2.m to the TA or instructor.

Student Questions and Answers

Questions? Please post them on the Google Group http://groups.google.com/group/wustl-matlab.

Personal tools