All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Our objective is to write a program that solves the following ODE. The following ODE represents the equation of motion of a simple pendulum with damping. d2θdt2+bmdθdt+gLsinθ=0 where, g = gravity in m/s2, L = length of the pendulum in m, m = mass of the ball in kg, b = damping coefficient.…
Smitesh Badnapurkar
updated on 24 Dec 2020
Our objective is to write a program that solves the following ODE.
The following ODE represents the equation of motion of a simple pendulum with damping.
d2θdt2+bmdθdt+gLsinθ=0
where,
g = gravity in m/s2,
L = length of the pendulum in m,
m = mass of the ball in kg,
b = damping coefficient.
Given data:->
L = 1 meter,
m = 1 kg,
b = 0.05.
g = 9.81 m/s2.
At initial condition, time = 0, angular displacement = 0, angular velocity = 3 rad/s^2.
Time span = 0 to 20 seconds.
MATLAB/ Octave has standard solver for solving ordinary differential equations (ODEs) the function is "ODE45". This function calculate solutions of ODEs by using Numerical method i.e. Runge-Kutta method for a time domains at variable time steps. Function syntax is as follows.
Output = ode45("Function", "time", "Initial condition")
For coding we are using ODE45 solver. In following code an anonymous function f(t,theta) is used.
here, consider angular displacement = theta = theta(1)
for angular velocity i.e.dθdt =θ2=dθ1dt
For angular acceleration, d2θdt2= −(bm(θ2))−(gLsinθ1)
And initial condition is given by θ0
Octave code:-
clear all
close all
clc
l=1; %Length of pendulum string in meter
m=1; %Mass of pendulum in kg
b=0.05; %Damping coefficient
g=9.81; %Gravitational acceleration in (N/m^2)
t=linspace(0,20,100); %time span 0 to 20 seconds with 100 time steps.
theta0=[0 3]; %initial conditions [angular displacement Angular velocity]
%Ordinary differential equation function
[t, theta]= ode45(@(t,theta) [theta(2) ; -(b*theta(2)/m)-(g*sin(theta(1))/l)], t, theta0);
%Here theta is angular displacement which is shown by theta(1)
%Rate of change of theta is angular velocity which is shown by theta(2)
%Rate of change of theta(2) is angular acceleration
% Creation of graph resulting magnitude of angular velocity & displacement w.r.t time
figure(1);
plot(t,theta(:,1),'color','b'); %plotting time v/s angular displacement
hold on;
plot(t,theta(:,2),'color','r'); %plotting time v/s angular velocity
legend('Angular displacement','Angular velocity');
xlabel('Time (Seconds)');
ylabel('Magnitude');
title('Pendulum plot for angular displacement & angular velocity')
for i= 1:length(theta(:,1))
figure(2)
clf;
%origin of pendulum (x0,y0)(Constrain point)
x0=0;
y0=0;
% Other end of pendulum (x1,y1) (Centre of bob)
x1=l*sin(theta(i,1));
y1=l*cos(theta(i,1));
plot([-1 1], [0 0]);
hold on;
line([x0 x1], [-y0 -y1]);
plot(x1,-y1,"0",'markersize',40,'markerfacecolor','g'); % Plotting of bob
grid on;
axis([-1.5 1.5 -1.5 0.5]); %axis dimensions
title('Pendulum animation');
printf('Creating GIF- Progrss... %d/%dn', i, length(t));
img = print('-RGBImage');
imwrite(img, 'animation.gif', 'DelayTime', 0.1,'Compression','bzip','WriteMode','append');
endfor
After running above we get output plot of time v/s magnitude of angular velocity & angular displacement
And we get animation of pendulum for time scale 0 to 20 seconds.
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Discretization of 3D intake manifold using GEM-3D
Aim:-> To perform discretization of intake manifold with converting it in 1D circuit model from 3D model and observing effect of discretization length on result. Theory: Discretization is the splitting of large parts into smaller sections to improve a model's accuracy. There are two ways in which a fluid…
07 Sep 2021 03:50 PM IST
Conjugate heat transfer analysis of exhaust Port
Aim:-> Conjugate heat transfer (CHT) analysis of exhaust port. Theory:- As we know heat is transferred by 3 modes i.e. Conduction, convection & radiation. Conduction:- is an exchange of energy by direct interaction between molecules of a substance containing temperature differences. Convection:- is…
20 Aug 2021 02:07 PM IST
Turbocharger Modelling using GT Power
Aim:-> Study of turbocharger and its modeling using GT Suit. Theory:- A turbocharger (technically a turbosupercharger), colloquially known as turbo, is a turbine-driven, forced induction device that increases an internal combustion engine's power output by forcing…
20 Aug 2021 08:11 AM IST
Comparison of CI and SI engine and calibration of Single cylinder CI-Engine
Aim:-> To compare SI and CI engine and perform basic calibration of single cylinder CI engine. Comparison of SI V/S CI Engine model: SI Engine CI Engine SI engine is internal combustion engine that operates on the principle of spark ignition. CI engine is internal combustion engine that operates on the principle…
20 Aug 2021 08:09 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.