Project

Transient Behavior of a Simple Pendulum using MATLAB

OBJECTIVE:

  • To solve the ODE which represents the equations of motion in a simple pendulum with damping by writing MATLAB code.
  • To simulate the motion of a simple pendulum with damping with MATLAB code.

MATHEMATICAL FORMULATION:

The ODE is of 2nd order which represents the equations of motion in a simple pendulum is given by,

In the above equation, g = gravity (m/s2); L = length of the pendulum (m); m = mass of the ball (kg); b=damping coefficient.

We introduce a variable,

Differentiate with respect to time we get,

Substituting these values in the ODE we end up with,

Writing the two first order equations in a matrix form the 2nd order ODE will be reduced to the following:

MATLAB CODING:

function [theta_dot]=pendulum_ode(t,theta)
L=1;% m
m=1;% kg
b=0.05;%damping coefficient
g=9.81; % m/s2
theta_dot=zeros(2,1);
theta_dot(1)=theta(2);
theta_dot(2)=(-b/m)*theta(2)-(g/L)*sin(theta(1));
end
clear all 
close all 
clc

theta0 = [0 3]; % Value of angular displacement and angular velocity
t = linspace(0,20,1000); %simulation time of (0 - 20 s)


[t,theta]=ode45('pendulum_ode',t,theta0);


figure(1)
plot(t,theta(:,1),'color','green')
xlabel('Time (s)')
hold on
plot(t,theta(:,2),'color','blue')
hold off
legend('Angular Displacement (rad)','Angular Velocity (rad/s)')

figure(2)
plot(theta(:,1),theta(:,2))
xlabel('Angular Displacement (rad)')
ylabel('Angular Velocity (rad/s)')
hold on

figure(3)
L=1;
ct=1;
for i=1:length(theta(:,1))
    
    x0=0;
    y0=0;
    x1=L*sin(theta(i,1));
    y1=-L*cos(theta(i,1));
    
    plot([-1 1],[0 0],'linewidth',6,'color','red')
    hold on
    plot([x0 x1],[y0 y1],'linewidth',4,'color','yellow')
    hold on
    plot(x1,y1,'-o','markers',10,'markerfacecolor','black')
    hold on
    axis equal
    grid on
    axis([-1.5 1.5 -1.5 0.5])
    hold off
    M(ct)=getframe(gcf);
    ct=ct+1;
end

movie(M)
videofile=VideoWriter('forward_kinematics.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

OUTPUT:

  • We see that the motion of the pedulum is peroidic without a drastic change of angular displacement or velocities. But when the value of damping coefficient is increased by a factor of 10, the metal bob of the pendulum sees a decrease in its angular components and comes back to its orginal position by taking less time for simulation.
  • For our results when we increase the length of simulation time the pendulum will come and rest in its orginal position.

CONCLUSION:

Thus the motion of a simple pendulum was simulated using MATLAB code.

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.