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

Need help with creating a pendulum in Matlab. DO NOT COPY PASTE FROM SOMEWHERE E

ID: 2247159 • Letter: N

Question

Need help with creating a pendulum in Matlab. DO NOT COPY PASTE FROM SOMEWHERE ELSE!!

pendulum example: https://www.dropbox.com/s/g228uu2bskn9i8o/pendulum_example.avi?dl=0

This is what I've done so far, but the video I get from this results causes the pendulum to go around a full circle instead of 60 degrees likes its supposed to .

L = 2

g = 9.81

T = 2*pi*sqrt(L/g)

myVideo2 = VideoWriter('pendulum')

open(myVideo2)

set(figure, 'Visible', 'on')

for t = 0:0.001:T;

theta = 60*cos(sqrt(g/L*t));

x = L*sin(theta);

y = L*(1 - cos(theta));

x2 = [0 x];

y2 = [L y];

plot(x, y, 'b.', 'MarkerSize', 40)

hold on

plot(x2, y2,'k' ,'linewidth', 3)

hold off

axis equal

axis([-2,2,-2,2])

drawnow

frame = getframe;

writeVideo(myVideo2, frame)

end

close(myVideo2)

The motion of a pendulum (more specifically, the "bob" at the end of the pendulum) can be described mathematically by the equations y: L(1-cos()) Here x and y are the coordinates of the bob at time t , and ("theta") is the angle the rod makes with the vertical (see Figure 4.3). The parameters in this model are the the length of the rod L, the acceleration due to gravity g and the initial angle

Explanation / Answer

// this is for only one rotation

L = 2

g = 9.81

T = 2*pi*sqrt(L/g)

myVideo2 = VideoWriter('pendulum')

open(myVideo2)

set(figure, 'Visible', 'on')

for t = 0:0.001:T/30;

theta =60+ 60*cos(sqrt(g/L)*t));

x = L*sin(theta);

y = L*(1 - cos(theta));

x2 = [0 x];

y2 = [L y];

plot(x, y, 'b.', 'MarkerSize', 40)

hold on

plot(x2, y2,'k' ,'linewidth', 3)

hold off

axis equal

axis([-2,2,-2,2])

drawnow

frame = getframe;

writeVideo(myVideo2, frame)

end

close(myVideo2)