Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my code for MATLAB for simulating the motion of a swing: x = [-1 , 1, 1,

ID: 3811224 • Letter: T

Question

This is my code for MATLAB for simulating the motion of a swing:

x = [-1 , 1, 1, 1,-1 ];

y = [-1/3,-1/3, 0, 1/3, 1/3];

g = hgtransform;

patch('XData',x,'YData',y,'FaceColor','black','Parent',g)

axis equal

xlim([-11 11])

ylim([-11 11])

xs = linspace(-10,10,100);

ys = 10*cos(xs);

ampx = 8;

ampy = 6;

w = 1;

phi = 0;

damp = .01;

e = exp(1);

et = (e^(-damp*t));

for t=linspace(0,28*pi/2,5600)

g.Matrix = makehgtform('translate',-ampx*et*cos(w*t+phi),-ampy*et*((sin(w*t+phi))^2),0);

drawnow

end

I NEED TO ADD 2 things:

1. a vertical line at each end of the swing, to act as the cords

2. I need to get the swing to slow down and come to a stop over time like a normal swing would,

but the swing should continue to stay on the same arc (also like a normal swing does)

please help!

x 3 [-1 1, 1, 1,-1 y 1/3 0, 1/3 1/3] g hgtrans form patch XData YData y Face Color black Parent g) axis equal x lim [-11 11]) ylim( [-11 11]) xs 3 linspace (-10, 10, 100) ys 10*cos (xs) ampx ampy phi 30;I damp 01 e 3 exp (1) et 3 (e (-damp*t)) for t linspace (0,28*pi/2,5600) g.Matrix 3 makehgt form translate et cos (w*t+phi) ampyxetxa (sin (wxt +phi)) 2) ,0); drawnow end

Explanation / Answer

For

1)

line([0 0], [-11 11]); % this will give vertical lone between points which can acts as cords
line([-11 11], [-11 11]); % right side vertical line

2)

pause(0.01) after drawnow statement will make plotting slow motion..

Integrated code..

x = [-1 , 1, 1, 1,-1 ];
y = [-1/3,-1/3, 0, 1/3, 1/3];
g = hgtransform;
patch('XData',x,'YData',y,'FaceColor','black','Parent',g)
axis equal
xlim([-11 11])
ylim([-11 11])
xs = linspace(-10,10,100);
ys = 10*cos(xs);
ampx = 8;
ampy = 6;
w = 1;
phi = 0;
damp = .01;
e = exp(1);
et = (e^(-damp*t));
for t=linspace(0,28*pi/2,5600)
   g.Matrix = makehgtform('translate',-ampx*et*cos(w*t+phi),-ampy*et*((sin(w*t+phi))^2),0);
   drawnow
   pause(.01) % putting this statement will make you feel that .. swinging like a cradle in movie, it will slow down the plotting
end
line([0 0], [-11 11]); % this will give vertical lone between points which can acts as cords
line([-11 11], [-11 11]); % right side vertical line

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote