Project

SIMULATION OF TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM AND ANIMATING IT'S MOTION

AIM: SIMULATION OF TRANSIENT BEHAVIOUR OF A SIMPLE PENDULUM AND ANIMATING IT'S MOTION

OBJETICVES:

Writing a program in Matlab\Octave to simulate the pendulum motion.
using physcial parameters.
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s2.
Simulation of the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.

DSECRIPTION:

In engineering systems, ODE i.e. ordinary differential equation is used to describe the transient behavior of a system. A very basic and simple example is a pendulum. The second order Ordinary Differential Equation for motion of a pendulum is given by:

Terms used In the above equation are

g= gravity in `m/s^2`
l=length of pendulam in m
m=mass of the ball in kg
b=damping coefficient

And values of these coefficients are mentioned in the objective above.

CODE USED:

%input the physical values i.e b,g,l,m
%In the  equation,
%g = gravity in m/s2,
%L = length of the pendulum in m,
%m = mass of the ball in kg,
%b=damping coefficient.

theta_0=[0;3];
time_span=linspace(0,20,500);
[Result]=lsode('fxn_ode',theta_0,time_span);

l=1;

%plotting graph time vs angular displcement and angular velocity

figure(1)
hold on
plot(time_span,Result(:,1),'color','b','linewidth',4)
plot(time_span,Result(:,2),'color','r','linewidth',4)
xlabel('Time')
ylabel('Velocity and Displacement')



%for animation
anitheta=Result(:,1);
ct=1;

for i=1:length(anitheta)
T3=anitheta(i);
x0=0;
y0=0;
x1=(l*sin(T3));
y1=-(l*cos(T3));

figure(2)
%for surface line
plot([-1 1],[0 0],'color','g','linewidth',3);
hold on


%for point of contact of wire and suface
plot([0 0],[0 0],'o','markerfacecolor','b','markersize',15);
hold on


%for wire representation
plot([x0 x1],[y0 y1],'color','b','linewidth',3);
hold on

%for bob representation
plot(x1,y1,'o','markerfacecolor','r','markersize',40);
hold off

axis([-1.5 1.5 -1.5 1])
pause(0.002)  

ct=ct+1;
end

FUNCTION "fxn_ode" used is :

function [dtheta_dt]=fxn_ode(theta,time)

b=0.05;
m=1;
l=1;
g=9.81;

theta1=theta(1);
theta2=theta(2);

dtheta1=theta2;
dtheta2=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1;dtheta2];
end

STEP WISE EXPLANATION :

STEP 1: In this step the time_span array was created using linspace command and the value at t=0 was initiated. The ode was solved at different time using "lsode" inbuilt function and the matrix representation was done using the self made function "fxn_ode" whose explanation is below.The result was stored in "Result" array.

STEP 2: In this step the theta1 and theta2 were plotted against the time span.xlabel and ylabel were used to identify the axes meanings.

STEP 3: To create the animation the result column was stored in a new array "anitheta" and then the for loop was used.As x1 y1 are known from the diagram itself.

STEP 4: In this step the plots for motion of the pendulum at each time were created and then mixing of them containing each frame was converted into animation representing the motion of the pendulum.

STEP 5: In this last step the axes were shifted in order to visualise the graphs and pause was used to show the frames of the pendulum motion.

OUTPUT GRAPH AND SAMPLE MOTION:

ERRORS DURING PROFRAMMING:

1. It was a syntax error in which during the plot commond extraction of 1st column from Result array was to be done.

This was overcame by using the correct syntax " (:,1)" because comma was missing before.

2. In this error "hold off" command was not previously not used that resulted in the wrong images for the figure(2). This was overcame by using corrected command.

corrected command

Error image generated.

RESULT: The resulted animation link is as below.

https://youtu.be/RNYQ4MK1VJA

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.