Placement 2025 Scholarship: Your Future Starts Here | 6 Guaranteed Job Interviews | Limited to 100 seats. Apply Now

04D 01H 54M 11S

Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Placements

Student Reviews


For Business


More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

All Courses

All Courses

logo

CHOOSE A CATEGORY

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

Top Job Leading Courses

Automotive

CFD

FEA

Design

MBD

Med Tech

Courses by Software

Design

Solver

Automation

Vehicle Dynamics

CFD Solver

Preprocessor

Courses by Semester

First Year

Second Year

Third Year

Fourth Year

Courses by Domain

Automotive

CFD

Design

FEA

Tool-focused Courses

Design

Solver

Automation

Preprocessor

CFD Solver

Vehicle Dynamics

Machine learning

Machine Learning and AI

POPULAR COURSES

coursePost Graduate Program in Hybrid Electric Vehicle Design and Analysis
coursePost Graduate Program in Computational Fluid Dynamics
coursePost Graduate Program in CAD
coursePost Graduate Program in CAE
coursePost Graduate Program in Manufacturing Design
coursePost Graduate Program in Computational Design and Pre-processing
coursePost Graduate Program in Complete Passenger Car Design & Product Development
Executive Programs
Workshops
For Business

Success Stories

Placements

Student Reviews

More

Projects

Blogs

Academic Training

Find Jobs

Informative Articles

We're Hiring!

phone+91 9342691281Log in
  1. Home/
  2. Aniket Kumbhar/
  3. Project 2 - MATLAB - second order ODE - Simple Pendulum.

Project 2 - MATLAB - second order ODE - Simple Pendulum.

   AIM:  Make a Mat Lab code to solve and generate plot for Simple Pendulum.  OBJECTIVE:                      Make a Mat Lab code to solve and generate plot for Simple Pendulum. The code should create…

  • MATLAB
  • Aniket Kumbhar

    updated on 06 Jun 2022

 

 AIM:  Make a Mat Lab code to solve and generate plot for Simple Pendulum.

 OBJECTIVE:

                     Make a Mat Lab code to solve and generate plot for Simple Pendulum. The code should create to simulate the motion of a pendulum by solving the equation that represent

The damping pendulum.

 SOLUTION:

                      A Mat Lab code was written for Simple Pendulum. To find the velocity and displacement at the different state points. Further, the code generates a plot for it. With respect to the input variables given and also we generate the output video.

 Explanation:

                      The aim of the program is to solve and generate plot for Simple Pendulum.

ODE is used for transits the equation of behaviour of simple system, the simple example is the pendulum. The way the pendulum is moves it depend on the newton’s low. When we wright the low the second order ODE (ordinary differential equation) it define the position of ball w.r.t. time.  The ODE represent the equation of motion of a simple pendulum damping,

Here in above equation,

                               g = 9.81 - gravity in m/s^2

                               l = 1 - length of the pendulum in meter

                               m =1 - mass of ball in kg

                               b =0.05 - damping coefficient in kg

Now we simulate the motion between 0 – 20 sec, for angular displacement is = 0.

Angular velocity – 2 rad/sec^2 at time = 0.

                 Fig:  SIMPLE PENDULUM

By solving this eq., we get value of theta 1 & 2 for simple pendulum. Using the ode45 function in the Mat-Lab to solve this ODE’s.

Procedure –

 %ODE represent the equation of motion of simple pendulum with damping

%the given teams

%damping coefficient in kg

b = 0.05;

%gravity in m/s^2

g = 9.81;

%Length of pendulum in m

l = 1;

%Mass of ball in kg

M = 1;

%Input conditions

theta_0 = [0;2.5];

% time

t_span = linspace(0,20,250);

 above parameters are the input parameters for pendulum condition

 For calculating ODE equation using function ode45 -

 The matlab allows to solution of first order ODE’s using the inbuilt function called ‘ode45’.

So the given second order ODE will reduce to two first order ODE in order to be solver using MATLAB. The given ODEE represent the variation of the position of pendulum w.r.t. time.

 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

 To find out ODE & plot  â€“

 %to solve ODE

[t, results] = ode45(@(t,theta) ode_func(t, theta, b,g,l,M),t_span, theta_0);

plot(t,results(:,1))

hold on

grid on

plot(t,results(:,2));

ylabel('time in second')

xlabel('plot')

 To make animation   â€“

 %to make the animation we have to use for looping

%counter variable for tracking the counter variable

 ct = 1;

 for i = 1 : length(results(:,1))

    x0 = 0;

    y0 = 0;

    x1 = 1*sin(results(i,1));

    y1 = -1*cos(results(i,1));

    figure(2)

    %to make dead fix support

    plot([-1 1], [0 0], 'linewidth',15, 'color','b')

    axis([-2 2 -2 2])

    hold on

    %for plotting string possition

    line([x0 x1], [y0 y1], 'linewidth', 5,'color','r')

    %plot ball position

    plot(x1, y1, 'o','markersize', 25, 'markerfacecolor', 'y')

    hold off

    m(ct) = getframe(gcf)

    %store current frame

    ct = ct+1;

end

 To make movie output –

 To save the animation of pendulum moment while time period will be saved by following program

 %to create video output

 movie(m)

videofile = VideoWriter('pendulum_simulation.avi', 'Uncompressed AVI');

 %to open video

open(videofile);

 %write frame to video file

writeVideo(videofile, m)

 %close video file

close(videofile)

 THE MAIN PROGRAM - 

%THE SIMPLE PROGRAM TO DEFINE THE SECOND ORFER ODE FOR PENDuLUM. 
%ODE - ORDNARY DIFFRENTIAL EQUATION

close all
clear all
clc

%ODE represent the equation of motion of simple pendulum with damping
%the given tearms 
%damping coefficient in kg 
b = 0.05;
%gravity in m/s^2
g = 9.81;
%Length of pendumum in m
l = 1;
%Mass of ball in kg
M = 1;
%Input conditions
theta_0 = [0;2.5];
% time 
t_span = linspace(0,20,250);

%to solve ODE
[t, results] = ode45(@(t,theta) ode_func(t, theta, b,g,l,M),t_span, theta_0);
plot(t,results(:,1))
hold on
grid on
plot(t,results(:,2));
ylabel('time in second')
xlabel('plot')


%to make the animation 

%counter variable for tracking the counter variable 
ct = 1;

for i = 1 : length(results(:,1))
    
    x0 = 0;
    y0 = 0;
    x1 = 1*sin(results(i,1));
    y1 = -1*cos(results(i,1));
    figure(2)
    %to make dead fix support 
    plot([-1 1], [0 0], 'linewidth',15, 'color','b')
    axis([-2 2 -2 2])
    hold on 
    %for plotting string possition 
    line([x0 x1], [y0 y1], 'linewidth', 5,'color','r')
    %plot ball position 
    plot(x1, y1, 'o','markersize', 25, 'markerfacecolor', 'y')
    hold off 
    m(ct) = getframe(gcf)
    %store current frame
    ct = ct+1;
    
end


%to creat video output 
movie(m)
videofile = VideoWriter('pendulum_simulation.avi', 'Uncompressed AVI');
%to open video 
open(videofile);
%write frame to video file 
writeVideo(videofile, m)
%close video file 
close(videofile)


function 


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









 

YOUTUBE LINK FOR VIDEO -

https://youtu.be/l-S9kKJJ16c

 

Conclusion   â€“

 The effect of dampings on pendulum.

The displacement of the pendulum keep reduced while progressing thiem due to effect of damper the velocity of pendulum keep decrese with time.

The program has successfully run. The plot time w.r.t the velocity & displacement.

There are so many errors occurs wile programming, are attached in attachments & the most of errors are occurs while typing program. Its only reducing by practising for typing the program.

 

YOUTUBE LINK FOR VIDEO -

https://youtu.be/l-S9kKJJ16c

 

                              fig; the final plot.

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.

Please  login to add a comment

Other comments...

No comments yet!
Be the first to add a comment

Read more Projects by Aniket Kumbhar (24)

Week 11 - Final project

Objective:

Aim: To Creation of CAD model considering Class A surface, Nominal thickness and Attachment strategy.   Objective: To Creation of CAD model considering Class A surface, Nominal thickness and Attachment strategy. Create thickened part using master section for reference Create the mounting features as per design guidelines…

calendar

05 Jan 2023 11:12 AM IST

  • CATIA
Read more

Hood design-Week 2

Objective:

HOOD DESIGN OF A CAR AIM : To design the hood of a car with the given input Outer panel and its dimensions.   Hood Introduction :   The hood (North American English) or bonnet (Commonwealth English) is the hinged cove over the engine of motor vehicles. Hoods can open to allow access to the engine compartment…

calendar

01 Nov 2022 10:50 AM IST

  • BIM
  • CAE
  • CFD
  • CSS
  • DEM
  • DESIGN
  • FEA
  • GIS
  • HEV
  • MBD
Read more

Week 8 - Challenge 4 - Bumper

Objective:

BUMPER DESIGN AIM: to make a model from the provided class-A surface.INTRODUCTION:CLASS-A SURFACE: a surface made by the designer which is given as an input to the plastic modeler to work on. It is aesthetic surfaceand the outer most surface.CLASS-B SURFACE: a surface below a certain thickness from the class-A…

calendar

18 Sep 2022 08:20 PM IST

  • BIM
  • CAE
  • CFD
  • CSS
  • DEM
  • DESIGN
  • FEA
  • GIS
  • HEV
  • MBD
Read more

Week 10- Assembly Workbench

Objective:

AIMIn this week’s assignment, you will have to create 2 assemblies according to the contentcovered in the course videos. You will be provided with 2D diagrams of the componentsand you will have to first create the individual part files and then create a completeassembly of those part files in the assembly workbench.…

calendar

14 Sep 2022 01:38 PM IST

  • BIM
  • CAE
  • CFD
  • CSS
  • DEM
  • FEA
  • GIS
  • HEV
  • MBD
  • QGIS
Read more

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

Related Courses

coursecard

Simulation and Design of Power Converters for EV using MATLAB and Simulink

4.9

22 Hours of Content

coursecard

Introduction to Hybrid Electric Vehicle using MATLAB and Simulink

4.8

23 Hours of Content

coursecardcoursetype

Mechanical Engineering Essentials Program

4.7

21 Hours of Content

coursecard

Vehicle Dynamics using MATLAB

4.8

37 Hours of Content

coursecard

Introduction to CFD using MATLAB and OpenFOAM

4.8

13 Hours of Content

Schedule a counselling session

Please enter your name
Please enter a valid email
Please enter a valid number

logo

Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.

https://d27yxarlh48w6q.cloudfront.net/web/v1/images/facebook.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/insta.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/twitter.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/youtube.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/linkedin.svg

Our Company

News & EventsBlogCareersGrievance RedressalSkill-Lync ReviewsTermsPrivacy PolicyBecome an Affiliate
map
EpowerX Learning Technologies Pvt Ltd.
4th Floor, BLOCK-B, Velachery - Tambaram Main Rd, Ram Nagar South, Madipakkam, Chennai, Tamil Nadu 600042.
mail
info@skill-lync.com
mail
ITgrievance@skill-lync.com

Top Individual Courses

Computational Combustion Using Python and CanteraIntroduction to Physical Modeling using SimscapeIntroduction to Structural Analysis using ANSYS WorkbenchIntroduction to Structural Analysis using ANSYS Workbench

Top PG Programs

Post Graduate Program in Hybrid Electric Vehicle Design and AnalysisPost Graduate Program in Computational Fluid DynamicsPost Graduate Program in CADPost Graduate Program in Electric Vehicle Design & Development

Skill-Lync Plus

Executive Program in Electric Vehicle Embedded SoftwareExecutive Program in Electric Vehicle DesignExecutive Program in Cybersecurity

Trending Blogs

Heat Transfer Principles in Energy-Efficient Refrigerators and Air Conditioners Advanced Modeling and Result Visualization in Simscape Exploring Simulink and Library Browser in Simscape Advanced Simulink Tools and Libraries in SimscapeExploring Simulink Basics in Simscape

© 2025 Skill-Lync Inc. All Rights Reserved.

              Do You Want To Showcase Your Technical Skills?
              Sign-Up for our projects.