During the semester our department has traditionally had a fairly simple conservation of momentum lab. An air track is used and carts are collided in 1-D. Students can do sticky collisions and approximately elastic collisions and compare initial momentum and KE with the final momentum and KE. Its a nice simple experiment that highlights the basics of what we are doing in class.
I wanted to capture this for my online class. So I wrote a simple script that carries out the sticky collision – leaving the elastic collisions for the much harder 2-D molecular collision lab.
Here is the assignment:
Download and run the attached Matlab File on Sticky Collisions
Run it for the following parameters, and confirm what happens with your own calculation.
Run 1: m1 = 1, m2 = 1, v1 = 2, v2 = 0
Run 2: m1 = 4, m2 = 1, v1 = 2, v2 = 0
Run 3: m1 = 1, m2 = 4, v1 = 2, v2 = 0
Run 4: m1 = 1, m2 = 1, v1 = 2, v2 = 0.5
Run 5: m1 = 1, m2 = 1, v1 = 0.5, v2 = 2
Explain in as much detail as possible what is happening in line 47-54.
The Matlab file is here:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Animation of 1D sticky problem %%%%
%%%% Written by Matthew Wright %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Masses and Initial Speeds
m1 = 1;
m2 = 1;
v1 = 2;
v2 = 0;
%% Initial Position Targets
x1 = -8;
x2 = 0;
%% BlockSize
w1 = 1;
w2 = 4;
%% TimeStep
dt = 0.01;
%% Build the picture
plot ([-10, 10], [-0.5, 10], 'w')
hold on
plot ([-10, 10],[0,0],'-k', 'Linewidth', 3);
hold off
rec1 = rectangle ('Position', [x1-w1/2,0,w1,2], 'FaceColor', 'r');
rec2 = rectangle ('Position', [x2-w2/2,0,w2,2], 'FaceColor', 'b');
%Display
textToDisplay1 = ['Time: ', num2str(0)];
textholder1 = text (-8, 8, textToDisplay1);
textToDisplay2 = ['Mom1: ', num2str(m1*v1)];
textholder2 = text (-8, 7.5, textToDisplay2);
textToDisplay3 = ['Mom2: ', num2str(m2*v2)];
textholder3 = text (-8, 7, textToDisplay3);
%% Set into motion
time = 0;
myTest = 1;
pass = 1;
while time < 10
% do the collision
if myTest == 1
if x1 + w1/2 >= x2 - w2/2
v = (m1 * v1 + m2 * v2) / (m1 + m2);
v1 = v;
v2 = v;
myTest = 0;
end
end
%Calculate the position of the retangles
x1 = x1 + v1 * dt;
x2 = x2 + v2 * dt;
time = time + dt;
%update the position of the rectangles
set(rec1,'Position', [x1-w1/2,0,w1,2]);
set(rec2,'Position', [x2-w2/2,0,w2,2]);
%Display
textToDisplay1 = ['Time: ', num2str(time)];
set(textholder1, 'String',textToDisplay1);
textToDisplay2 = ['Mom1: ', num2str(m1*v1)];
set(textholder2, 'String',textToDisplay2);
textToDisplay3 = ['Mom2: ', num2str(m2*v2)];
set(textholder3, 'String',textToDisplay3);
drawnow %draw the frame
end
The students did very well on this assignment.
I was able to integrate into the “lecture” (whatever the #$%^# that means on an online class) component in the class ala studio physics.
Students were asked to explain the code and use this an opportunity to reinforce the scientific computing part of the class.
The big downside is that this code runs incredibly slow for the students who have MATLAB online for some reason.




Leave a Reply