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

Create a MATLAB program to simulate motion of a pendulum in 2-D. The pendulum is

ID: 1842176 • Letter: C

Question

Create a MATLAB program to simulate motion of a pendulum in 2-D. The pendulum is a uniform slender rod with its upper end inertially fixed with a frictionless pin joint. Use Euler integration to solve the equation of motion. The pendulum should have a length of 1 meter and a mass of 5 kg. First, plot and animate the motion of the pendulum for 5 seconds using an initial angle of 40 degrees and initial angular velocity of 0 deg/sec. You will need to determine dt such that the pendulum motion is as expected. Then, vary the time step until the pendulum becomes unstable. Plot and animate the motion. How does this compare to the motion simulated in #1 above? Why does this happen?

Explanation / Answer

solution:

here matlab code is given as follows

displacment or equation of motion is given by

m1=.5*alpha*t^2

alpha=w/t

m1=.5*w*t

it is radian so we get angle in degree by considering initial condition as

m=mo-m1

m=mo-(180/pi)*(w/2)*t

for first half

mo=320

next half

mo=230

matlab code:

clc;

clear all;

close all;

L=input('length of bar');

L1=L/2;

g=9.81;

w=sqrt(g/L1);

T=2*pi*sqrt(L1/g);

for t=0:.001:T/2

mo=320;

m=mo-(180/pi)*(w/2)*t;

end

for t=T/2:.001:T

mo=230;

m=mo+(180/pi)*(w/2)*(t-(T/2));

end

for t=T:.001:3*T/2

mo=320;

m=mo-(180/pi)*(w/2)*(t-T);

end

for t=3*T/2:.001:2*T

mo=230;

m=mo+(180/pi)*(w/2)*(t-(3*T/2));

end

for t=2*T:.001:5*T/2

mo=320;

m=mo-(180/pi)*(w/2)*(t-2*T);

end

for t=5*T/2:.001:3*T

mo=230;

m=mo+(180/pi)*(w/2)*(t-(5*T/2));

end

for t=3*T:.001:7*T/2

mo=320;

m=mo-(180/pi)*(w/2)*(t-3*T);

end

for t=7*T/2:.001:3.524841*T

mo=230;

m=mo+(180/pi)*(w/2)*(t-(7*T/2));

end

plot(t,m)

title('graph')

xlabel('value of time');

ylabel('pendulum position');