Project

Damped Pendulum

AIM

The aim of this challenge is to learn to solve ordinary differential equation in matlab.

OBJECTIVE

The main objective of this project is to write an program to solve the damped pendulum ordinary differential equation.

DAMPED PENDULUM

A pendulum is a body which is suspended body in the form of a mass called bob from a fixed support which exhibits the vibratory motion. It is free to oscillate about a mean position when a small force is given to the bob. Therefore, the equation of motion for the movement of the pendulum is governed by the ordinary differential equation which is given by

d2θdt2=bmdθdt+gLsin(θ)=0">d2θdt2=bmdθdt+gLsin(θ)=0d2θdt2=bmdθdt+gLsin(θ)=0

In order to solve the above equation, it has to be converted to first order equation to solve it in matlab. Hence we define some equations

Angular velocity is defined as dθ1dt=θ2">dθ1dt=θ2dθ1dt=θ2

Angular acceleration is defined as d2θ1dt2=dθ2dt">d2θ1dt2=dθ2dtd2θ1dt2=dθ2dt

Governing equation becomes `dθ2dt=-bmθ2-gLsin(θ1)">dθ2dt=−bmθ2−gLsin(θ1)dθ2dt=-bmθ2-gLsin(θ1)`

MATLAB CODE

clear all
close all
clc

% Time span
t = linspace(0,20,300);

% initial conditions
theta_0 = [0 3];

theta = lsode('odefun_check',theta_0,t);

figure(1)
subplot(3,1,1)
plot(t, theta(:,1),'color','r','linewidth',3)
xlabel('time')
ylabel('Theta(Rad)')

subplot(3,1,2)
plot(t, theta(:,2),'color','b','linewidth',3)
xlabel('time')
ylabel('Angular Velocity')

subplot(3,1,3)
plot(theta(:,1), theta(:,2),'color','g','linewidth',3)
xlabel('Theta(Rad)')
ylabel('Angular Velocity')

for i=1:length(theta(:,1))
x_0 = 0;
y_0 = 0;
x_1 = 1*sin(theta(i,1));
y_1 = -1*cos(theta(i,1));

figure(2);
plot([-0.5 0.5],[0 0],'linewidth',5,'color','b');
hold on
line([x_0 x_1],[y_0 y_1],'linewidth',3,'color','g');
hold on
plot(x_1,y_1,"marker", "o", "markersize", 20,"markerfacecolor", "r");
hold on

% x and y components of the velocity vector
u_x = (theta(i,2))*cos((theta(i,1)));
v_y = (theta(i,2))*sin((theta(i,1)));

quiver(x_1,y_1,(u_x/5),(v_y/5),'linewidth',2,'color','r','linestyle',"--")

axis([-2,2,-2,0.5]);
hold off;
pause(0.001);

% Creating GIF file using Ocatve
printf('Creating GIF- Progress... %d/%d\n', i, length(t_span));
img = print ('-RGBImage');
imwrite(img, 'animation.gif', 'DelayTime', .005, 'Compression', 'bzip', 'WriteMode', 'Append');
end

For matlab to solve the ordinary differential equation the initial boundary conditions should be specified by creating an array for time span and the angular displacement. When we move further in the code the "lsode" command is used to solve firest order equation solver for solution. In the subsequent lines of the code, we create plots for theta(rad), Angular velocity versus time to examine the behaviour of the damping effect on the pendulum.

function [theta_dot] = odefun_check(theta,t)
theta_dot = zeros(2,1);
theta_dot(1) = theta(2);
theta_dot(2) = -theta(2)*0.5-(sin(theta(1)))*9.81;
end

subprogram for the function code is also defined where we define a function for the damped pendulum which is later called in the main program.

RESULTS AND DISCUSSION

Animation of the damped pendulum shows us as the pendulum is oscillating it comes to a halt as there is wind resistance which is acting against it. Damping coefficient has an effect on the moving pendulum which shows us that it is a damped pendulum video. Initial conditions for the pendulum challenge show the angular displacement is from zero and the angular velocity is from 3 radians/second at t=0.

The last plot shows us the velocity profile for the angular displacement versus angular velocity which tells us about the velocity profile trend to showcase the importance of the same.

The YouTube link for the animation of this simulation is shown below

CONCLUSION

The simulation for the damped pendulum is performed and the analysis is carried out on how damping coefficient effects the motion of the pendulum.

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.