## Transcribed Text

1 Damped spring system
The attached “spring.m” is almost the same MATLAB file shared in Class 15. It
simulates the oscillation of an initially stretched block. It runs for 120 frames and
generates 120 images. If we compile the 120 images into a video (24 frames per
second), we get a 5 second video “spring.mp4”.
Watching it, we can see it is very very jiggly.
In the real world, things do not jiggle like this. Because in the real world, a lot of
the mechanical energy is dissipated into heat. We call such dissipation “the effect
of damping”.
1.1 Task 1
We learned in Class 16 about how to incorporate damping into a spring sys-tem.
Please add damping to this file with a damping coefficient equaling to 3.
At this stage, it is extremely recommended that you have already learned
some technique to generate a video file from a folder with png files. There are
many softwares (likely MATLAB too) that can achieve this. Google it and learn
it. You probably want to watch the video to help you debug your code!
1.2 Task 2
Qualitatively we can observe that the damped system looks more calm and
damped than the original system. To quantify this behaviour, we can try to
plot the total energy vs time step.
In the end of each of the 120 time steps, you can compute the current total
energy E as
E = KE + PE
where KE is the total kinetic energy, which can be computed as
KE =
X
p
1
2
mpkvpk
2
1
where for each point p, mp and vp are its mass and velocity respectively. The
total potential energy P E contains some elastic potential energy stored in each
edge, and can be computed as
P E =
X
e
Re
1
2
ke
Le
Re
− 1
2
.
Here e is a summation over edges. For each edge e, Re, Le and ke are its rest
length, current length, and stiffness respectively.
Your task is to plot the curve for Total energy vs step. Do it on both
spring.m and springDamper.m. Make sure the two plots have the same x and
y range. Submit the two plots as two images into Canvas: “energySpring.png”
and “energySpringDamper.png”. The expected behavior of the plots is: the
spring one oscillates, the damped one looses energy over time in a more stable
way.
Note that you are not required to submit your code for computing the energy
and doing these plots.

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

clc;

clear;

% parameters

M=12;

N=8;

number_points=M*N;

X=zeros(number_points,2);

V=zeros(number_points,2);

mass=ones(number_points,1)*0.5;

mesh=[];

dx=0.1;

dt=0.02;

stiffness = 20;

damping = 0.04;

writerObj = VideoWriter('springDamper');

writerObj.FrameRate=24;

open(writerObj);

% mesh construction

for i=1:M

for j=1:N

id = (j-1)*M+i;

X(id,:) = [(i-1)*dx, (j-1)*dx];

end

end

for i=1:M-1

for j=1:N-1

id = (j-1)*M+i;

mesh = [mesh; [id, (j-1)*M+i+1]];

mesh = [mesh; [id, j*M+i]];

mesh = [mesh; [id, j*M+i+1]];

mesh = [mesh; [(j-1)*M+i+1, j*M+i]];

end

end

for i=1:M-1

j = N;

id = (j-1)*M+i;

mesh = [mesh; [id, (j-1)*M+i+1]];

end

for j=1:N-1

i = M;

id = (j-1)*M+i;

mesh...