Several labs ago, we simulated a block on a spring attached to a
wall, and we saw how that block acted if we pulled. This week we are
going to model an elastic string as a large collection of stones,
attached to each other with springs, and see what shapes this becomes.
First, some physics. Imaging a stone hanging on springs connected to
(immovable) anchors on two walls:

It will eventually come to rest at the position (x,y) where:
We will figure out what Fgravity should be later, but Fleft and Fright will be calculated using Hooke's law:
where x is the displacement (how stretched the spring is), and the force x is now a vector pointing towards the other endpoint of the spring.
At the moment, let us assume that the spring constant "k" is 1, and that the "unstretched" length of the string is 0.5, so the displacement = (distance between two endpoints of string - 0.5)
First, compute Fleft and Fright for a stone at position (x,y). The below lines of code compute the force to the left. Test them, then put the into a function called computeFLeft (what should this function return?). This function should take in parameters (x,y,k)
dL = sqrt(x.^2 + y.^2); % distance to left anchor F = -k * (dL-0.5); % compute the force. vx = (x)./dL; vy = (y)./dL; % unit vector in direction towards left anchor Fx = F * vx; Fy = F * vy; % make the force vector.
Make a similar function computeFRight that computes the force to the right anchor. When you get these right, they should give the following results:
[Fx Fy] = computeFRight(0.5,-0.1,1)
Fx =
0.0097
Fy =
0.0019
>> [Fx Fy] = computeFLeft(0.5,-0.1,1)
Fx =
-0.0097
Fy =
0.0019
Now, to complete this task, we are going to simulate the motion of the stone, assuming that it starts with 0 velocity at position (0.3,0), and is acted on by the forces to the left, to the right, and gravity. We will use a value of 4 for "k". To do this, write a script which does the following:
% initialize position and velocity of the stone, and the value of "k" % initialize a time step dt % For loop, for 1000 steps: % Compute Fleft for the current position % Compute Fright for the current position % Compute Fgravity for the current position (assume the stone has % weight of 1 and use 9.8 m/s/s (so Fgravity will be 9.8). % Sum these vectors to get the total force. % Compute the total accelaration vector (F = ma, so, a = F/m); % use that acceleration to update the velocity (make sure to get % both the x and y components) % use that velocty to update the stone position % make a plot which shows the anchor positions and the stone (and % the springs) % Hint, do your plot commands, then use " axis([0 1 -2 1]) " before % your drawnow command to give it a good window to plot
Now run your simulation, does it do what you expect?
The reason that it doesn't ever "calm" down is that there is no friction in the system so it will continually vary. We can add friction in a cheap way with the lines:
vx = vx .* 0.99; vy = vy .* 0.99;Experiment with different values of "dt" until you find one where the system is approximately stable after 1000 steps.
Show this simulation to a TA for the first check-off
Experiment again with different parameters for dt and when you find one that lets the set of springs settle down in about 1000 steps, show this simulation to a TA for the final check-off