All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Here We can simulate the transient behaviour of a simple pendulum and to create an animation of it's motion. Below is the figure of simple pendulum Below is the Second order differential equation for simple pendulum: Input Values: b=0.05 (Damping coefficient) g=9.81 (gravity in m/s^2) l=1 (Length of pendulum…
Shlok Dixit
updated on 27 May 2022
Here We can simulate the transient behaviour of a simple pendulum and to create an animation of it's motion. Below is the figure of simple pendulum
Below is the Second order differential equation for simple pendulum:
b=0.05 (Damping coefficient) g=9.81 (gravity in m/s^2)
l=1 (Length of pendulum in meter) m=1 (Mass in Kg)
In intial condition Lets take, Assume,
Angular Dislplacement is 0 and Angular Velocity is 4 and
Time span is 0 to 20 sec, with 300 intervals.
Now solve ODE,
In matlab ode45 is the inubuilt solver for ODE,
Here ODE is the function of t and theta , t and theta are dependent and independent variables. Below is the syntax for ODE,
[t,result]=ode45(@(t,theta) ode_function(b,g,l,m,t,theta),t_span,theta_0)
We have called function of name ode_function into it and give a name to ode_function as [dtheta_dt]
First Simplify, Assume,
So, dtheta_dt=dtheta1_dt
Then, d^2theta_dt^2=d^2theta1_dt^2
=d dt(dtheta1 dt)
find below ODE function as name given "ode_function"
function [dtheta_dt]=ode_function(b,g,l,m,t,theta) 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
In above this function we have to find values for result. Result has two columns, 1st for displacement Thats why i am assigning,
theta1=theta(1) and theta2=theta(2)
The result part we will cover next,
Now, we will find values for displacement and velocity w.r.t. time in a matrix form of table result. Then call above ode_function into main program
CODE
close all clear all clc
b=0.05; l=1;
m=1;
g=9.81;
theta_0=[0;4];
t_span=linspace(0,20,300);
[t,result]=ode45(@(t,theta) ode_function(b,g,l,m,t,theta),t_span,theta_0); figure(1)
hold on
plot(t,result(:,1),'color','r');
plot(t,result(:,2),'color','b');
xlabel('Time')
ylabel('Displacemt/Velocity')
legend('Displacement','Velocity') grid on
In ode45 synatx we defining value of b,g,l,m are assumed and then we define time span
d initial conditions by theta_0
t_span an The result of above progrm as belows:
I used hold on command to show the result into one graph or frame and legend command to differentiate displacement and velocity.
I got error when not use hold command;
In order to create animation vbideo i used counter (ct) command and movie command.
M is the variable to store all the output result figures and use for loop to complete time span length(t) i.e. 300 intervals.
close all clear all clc
b=0.05; l=1;
m=1;
g=9.81;
theta_0=[0;4];
t_span=linspace(0,20,300);
[t,result]=ode45(@(t,theta) ode_function(b,g,l,m,t,theta),t_span,theta_0); figure(1)
hold on
plot(t,result(:,1),'color','r');
plot(t,result(:,2),'color','b');
xlabel('Time')
ylabel('Displacemt/Velocity')
legend('Displacement','Velocity') grid on
or i=1:length(t)
0=0; y0=0;
x1=l*sin(result(i,1)); y1=-l*cos(result(i,1));
figure(2)
plot([-2 2],[0 0],'linewidth',3,'color','r'); line([x0 x1],[y0 y1],'linewidth',4);
axis([-2 2 -2 2])
old on
plot(x1,y1,'o','markers',20,'markerfacecolor','g'); hold off
rid on
pause(0.03);
M(ct)=getframe(gcf)
in order to fix this i use axis([-2 2 -2 2])
I got another typographic error for wrongly used Videowriter command instead of used VideoWriter which.
Please find below link for Animation video of Simple Pendulum Single ODE
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...
Week 3 - External flow simulation over an Ahmed body.
Hello this is Shlok here in this we are going to discuss about the Ahmed bodyCimulation in CFD Ansys Fluent So beofre going furthur lets get a few details about Ahmed Body Ahmed body is a simplified vehicle body used for capturing basic yet charecteristic features seen in objects used in the automobile industry. It is…
01 Aug 2023 12:27 PM IST
Week 3.5 - Deriving 4th order approximation of a 2nd order derivative using Taylor Table method
AIM: To derive the fourth order approximations of a second order derivative using central differencing scheme, skewed right sided difference and skewed left sided difference with the help of taylor table method and to compare the analytical…
18 Jul 2023 09:03 AM IST
Week 2 - Flow over a Cylinder.
Aim: To Simulate the flow over a cylinder and explain the phenomenon of Karman vortex street Objective: 1.To Calculate the coefficient of drag and lift over a cylinder by setting the Reynolds number to 10,100,1000,10000 & 100000. (Run with steady solver) 2.Simulate the flow with the steady and unsteady case…
11 Jul 2023 05:55 PM IST
Project 1 : CFD Meshing for Tesla Cyber Truck
Objective : To Identifying & cleanup all the topological errors in the given Tesla Cyber Truck Car model. To create a surface mesh. To Create a wind tunnel around Tesla Cyber Truck Car . To create a volumetric mesh to perform an external flow CFD analysis simulation. Introduction : ANSA :…
26 Feb 2023 04:02 PM 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.