All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Abstract:- The work is focused on transforming Newtons 2nd Law of motion, which is in the form of a second-order differential equation into two ordinary differential equations (ODE) & writing a code using "ODE45" or "LSODE" function in MATLAB or Octave (depending on the programing language used) respectively to…
Pratik Ghosh
updated on 19 Jan 2021
Abstract:- The work is focused on transforming Newtons 2nd Law of motion, which is in the form of a second-order differential equation into two ordinary differential equations (ODE) & writing a code using "ODE45" or "LSODE" function in MATLAB or Octave (depending on the programing language used) respectively to simulate the harmonic motion of a pendulum. This ODE represents the equation of motion of a simple pendulum with damping.
In the above equation,
g = gravity in m/s2, L = length of the pendulum in m, m = mass of the ball in kg, b= damping coefficient.
g= 9.81 m/s2, L= 1 metre, m= 1 kg, b=0.05.
Simulate the motion between 0-20 sec, for angular displacement=0, angular velocity=3 rad/sec2 at time t=0.
Method:- The above-given equation is in the form of a second-order differential equation & in order to solve the equation in MATLAB or Octave we need to convert this equation into an ordinary differential equation (ODE). MATLAB allows the solution of first-order differential equations by using a special function called "ODE45" or "LSODE" in the case of older versions of Octave GUI. These special functions use the Runge-Kutta method with a variable time step for efficient computation. But we are given a second-order differential equation that represents the motion of the simple pendulum. To use these special functions we need to find a way to convert the second-order differential equation into two first-order differential equations.
We have, d2θdt2+bmdθdt+gLsinθ=0
Now consider, θ=θ1 & dθdt=dθ1dt=θ2
We can write d2θdt as ddtdθdt⇒ddtθ2
Substituting this in the equation we get, dθ2dt+bmθ2+gLsinθ1=0
Further, we can rearrange, dθ2dt=−bmθ2−gLsinθ1
where θ1= angular displacement & θ2= angular velocity
Now that we have sucesfully transformed the second order differential equation into first order differential equation we will need the geneal command for the function ODE45, which is given by
[t,results] = ode45 (@fname, time span, initial condition)
Function to solve the first-order ODE
function [dtheta_dt] = ode_function_pendulum(t, theta, b, m, L, g)
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
Main Code
clear all
close all
clc
%input parameters
m = 1; %mass of the bob
b = 0.05; %damping coefficient
g = 9.81; %acceleration due to gravity
L = 1; %length of the wire
ct = 1; %counter variable
%initial condition
theta_0 = [0;3];
%duration for oscillation
t_span = linspace(0,20,500);
%Solve the differential eqation by calling the function
[t, results] = ode45(@(t, theta) ode_function_pendulum(t, theta, b, m, L, g), t_span, theta_0);
%plot the Variation of angular displacement & angular velocity w.r.t time
figure (1)
hold on
plot (t,results(:,1))
plot (t,results(:,2))
xlabel ('x-axix')
ylabel ('y-axix')
grid on
title ('Variation of angular displacement & angular velocity w.r.t time', 'color', 'b')
theta2 = results(:,1);
for i = 1:length(theta2);
theta_x = theta2(i);
x0 = 0;
y0 = 0;
x1 = L*sin(theta_x);
y1 = -L*cos(theta_x);
%plot the pendulum motion
figure (2)
plot ([-0.5 0.5], [0 0], 'color', 'b', 'linewidth', 5);
hold on
plot ([x0 x1], [y0 y1], 'color', 'r', 'linewidth', 2)
hold on
plot (x1,y1, 'o', 'markers', 15, 'markerfacecolor', 'y')
hold off
grid on
axis ([-1.5 1.5 -1.5 0.5]);
pause (0.002)
M(ct) = getframe (gcf);
ct = ct+1;
end
movie (M)
videofile = VideoWriter ('pendulum.avi', 'Uncompressed avi');
open (videofile)
writeVideo (videofile, M)
close (videofile)
Observation:-
Reference
https://in.mathworks.com/help/symbolic/simulate-physics-pendulum-swing.html
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...
Visualize 2D Flow Simulation Through A Backward Facing Step For 3 Distinct Mesh Grid Size Using openFOAM & ParaView
Abstract:- The work is focused on simulating fluid flow through a backward-facing step channel that would be subjected to a sudden increase in the cross-sectional area, this would result in flow separation & reattachment zones. The geometry will be designed by creating vertices & then joining them to form blocks.…
19 Jan 2021 06:26 AM IST
Week 12 - Symmetry vs Wedge vs HP equation
Objective:- The work is focused on performing a CFD simulation for a flow through a cylindrical pipe with reference to Hagen Poiseuille's principle that refers to the laminar flow formation inside a smooth cylindrical tube. Since the computation will be carried out on a laptop, we will not be able to consider the entire…
19 Jan 2021 06:26 AM IST
Writing A MATLAB/Octave Code To Perform A 1D Super-Sonic Nozzle Flow Simulation Using Macormack Method.
Abstract:- The work is focused on writing a MATLAB/Octave code to simulate the isentropic flow through a quasi 1D supersonic nozzle using both the conservation and non-conservation forms of the governing equations and solving them using MacCormack's technique and compare their solutions by performing a grid dependency…
19 Jan 2021 06:24 AM IST
Writing A MATLAB/Octave Program To Solve the 2D Heat Conduction Equation For Both Steady & Transient State Using Jacobi, Gauss-Seidel & Successive Over Relaxation (SOR) Schemes.
Problem Statement:- 1. Steady-state analysis & Transient State Analysis Solve the 2D heat conduction equation by using the point iterative techniques that were taught in the class. The Boundary conditions for the problem are as follows; Top Boundary = 600 K Bottom Boundary = 900 K Left Boundary = 400 K Right Boundary…
19 Jan 2021 06:23 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.