All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
AIM: TO write a program that will simulate the motion of a simple pendulum GOVERNING EQUATIONS: A simple pendulum ,in its simple form consists of a heavy bob suspended at the end of a light inextensible, flexible string and the other end of the string is fixed at O. the pendulum…
Udaya Jyothi K
updated on 19 Jan 2021
AIM: TO write a program that will simulate the motion of a simple pendulum
GOVERNING EQUATIONS:
A simple pendulum ,in its simple form consists of a heavy bob suspended at the end of a light inextensible, flexible string and the other end of the string is fixed at O. the pendulum is in equilibrium when the bob is at A. If the bob is moved from B to C and released, it will start vibrating between the positions B and C with A as mean position.
Consider the equilibrium of the system at C,the weight mg of the bob can be resolved into two components i.e., mgcosθθ and mg sinθθ at right angles to each other. The mgcosθθ will act along the string and balances the tension in the string. The component mg sinθθ being unbalanced will give rise to an acceleration in the direction of CA.
In Engineering, ODE Order differential equations are used to describe the transient behavior of a system. Here we have taken the system as simple pendulum. The way the pendulum moves depends on Newton’s second law of motion. When this law is written down, second order ordinary differential equations describe the position of the ball w.r.t time.
d2θdt2=(bm)dθdt+(gL)sinθ=0d2θdt2=(bm)dθdt+(gL)sinθ=0
Where b=damping coefficient
m=mass of the ball, kg
g=gravity in m/s2
L=length of the pendulum in m
To solve this ODE, we have to integrate and solve for the variable. we use numeric solver by discretizing the equation that is we convert the ODE into a linear equation and then solve this equation to approximate the solution.
θ=θ1θ=θ1
dθdt=dθ1dt=θ2dθdt=dθ1dt=θ2 ------------1
d2θdt2=d2θ1dt2=d(dθ1dt)dt=d(θ2)dtd2θdt2=d2θ1dt2=d(dθ1dt)dt=d(θ2)dt--------2
Now substitute equation 1 and 2 in ODE of simple pendulum, d2θdt2=(bm)dθdt+(gL)sinθ=0d2θdt2=(bm)dθdt+(gL)sinθ=0
d2θ1dt2=(bm)dθ1dt+(gL)sinθ1=0d2θ1dt2=(bm)dθ1dt+(gL)sinθ1=0
dθ1dt=θ2dθ1dt=θ2----3
dθ2dt=-(bm)θ2-(gL)sinθ1dθ2dt=−(bm)θ2−(gL)sinθ1----4
when we solve the above linear equations 3 and 4, we get output results as below
d[θ1θ2]dt=[θ2-(bm)θ2-(gL)sinθ1]
OBJECTIVE:
Inputs:
L=1m
g=9.81m/s2
b=0.05
m=1kg
CODING:
The ODE45 function we use to solve ordinary differential equation is ode_func(). The variable we have taken here are time,t and angular displacement, theta. This function takes three inputs ,they are function which is to integrate , time span and the initial conditions.
The function is ode_func()
function[dtheta_dt]=ode_func(t,theta,b,g,l,m)
theta1 =theta(1);
theta2 =theta(2);
dtheta1_dt=theta2;
dtheta2_dt=(-b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end
The time span is 0 to 20 sec and in between 500 discrete values are taken so that at each value the angular displacement and velocity is calculated using ODE. The time span would be the integration limits which will be represented as a vector of 2 values the initial time and final time with a spacing using the linspace function. The output assigned to a variable t_span.
t_span=linspace(0,20,500)
Initial conditions is taken as column vector of two values ie.,first one is angular displacement value taken is zero and the second one is angular velocity i.e., the pendulum moves with an angular velocity of 3m/s at zero angular displacement.
theta_0=[0;3]
The function ode45 is in the form of an anonymous function,
[t, results] = ode45(@(t, theta) ode_func (t, theta, b, g, l, m),t_span,theta_0);
The output of this ode45 is a vector of two columns and 500 rows. The first column is the angular displacement and the second column is the corresponding angular velocity at each discrete value of time between the time span of 20 seconds. The obtained matrix is assigned to the variable 'results' .
The plot we get by taking the output values of ODE45 function, 'results' with respect to time t. The blue curve represents angular displacement aginst time stating at inital value theta=0. The orange curve represents angular velocity against time at initial value ,v=3m/s.
plot(t,results(:,1)) ---values of first column of results matrix against time are taken
hold on ---- hold on command is avoid overwrite the output results.
plot(t,results(:,2))-------values of second column of results matrix against time are taken
xlabel('Time')
ylabel('plot')
SIMULATION:
To do the simulation of the simple pendulum, we take for loop with a condition of i=1:results(:,1). here the variable results is the output of ODE45 function, which is a matrix of 2 columns and 500 rows.The first column values, angular displacement of the bob are taken for iteration of the loop. So at each value of angular displacement, x1 and y1 are calculated while x0 and y0 are taken as (0,0) and is fixed. For each iteration plot is captured and displayed in a single frame by using command getframe(gcf).
Marker command is used to create the bob of size 15 diameter and color red.
ct command is used to for each frame iteration.
clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=0.1;
theta_0=[0;3];
t_span=linspace(0,20,500);
[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('Time')
ylabel('plot')
figure(2)
ct=1
for i=1:length(results(:,1))
x0=0;
y0=0;
x1=l*sin(results(i));
y1=-l*cos(results(i));
plot([x0 x1],[y0 y1],'linewidth',3)
hold on
plot(x1,y1,'marker', 'o','markersize',15,'markerfacecolor','r');
hold off
axis([-1 1 -1 1]);
M(ct)=getframe(gcf)
pause(0.03)
ct=ct+1
end
movie(M)
videofile=VideoWriter('Simple Pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Errors: ODE function is given inside the for loop,got this error.
youtube link: https://youtu.be/VyheJuAXeW8
CONCLUSION: Using ODE functions we can solve many such system. These methods are of greater importance when we realise that computing machines are now available which reduces numerical work considerably. ODE45 function used in this program uses Ranga-Kutta Method.Many differential equations arising from physical problems are linear but have variable coefficients and do not permit a general solution in terms of known functions. such equation can be be solved by Numerical methods.
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...
Final Project: Design of an Electric Vehicle
Q. Create a MATLAB model of an electric car that uses a battery and a DC motor. Choose suitable blocks from the powertrain block set. prepare a report about your model including following Objectives 1. System-level configuration 2. Model parameters 3. results $.conclusion A: The Electric Vehicle…
18 Nov 2021 07:10 PM IST
Week-11 Challenge: Braking
The most important feature of electric vehicles and hybrid vehicles is their ability to absorb, store and reuse the braking energy. A successfully designed braking system for a vehicle must always meet two distinct demands. While applying the sudden brake, the vehicle must come to rest in the shortest possible distance…
03 Nov 2021 01:51 PM IST
Week-7 Challenge: DC Motor Control
Q1 A. Explain the MATLAB demo model named ‘Speed control of a DC motor using BJT H- bridge. Comment on the armature current shoot-up from the scope results Transistors have been used as amplification devices, where control of the base currents used to make the transistor conducive to a greater or lesser…
30 Aug 2021 08:25 AM IST
Week-6 Challenge: EV Drivetrain
which types of power converter circuits are employed in an electric and hybrid electric vehicle? The control inputs given by the vehicle brake and accelerate pedals are received by the electronic controllers produces control signals to the power source system through power devices. These…
09 Aug 2021 07:55 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.