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

00D 00H 00M 00S

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. Shaik Faraz/
  3. Week 3 - Solving second order ODEs

Week 3 - Solving second order ODEs

Aim:  Write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping       Write a program in MatlabOctave that will simulate the pendulum motion. Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec…

    • Shaik Faraz

      updated on 15 Apr 2022

    Aim:

     Write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping

         

    Write a program in MatlabOctave that will simulate the pendulum motion.

    Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.

    use,

    L=1 metre

    m=1 kg

    b=0.05

    g=9.81 m/s^2

    When you do this you will get the position of the pendulum as a function of time. Use this information to animate the motion of the pendulum.

     

    Theory:

    In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum

                                       Simple pendulum

    The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time. 

    The second order ode of simple pendulum is defind as

    2nd order ode

    where,

    g = gravity in m/s2,

    L = length of the pendulum in m,

    m = mass of the ball in kg,

    b=damping coefficient.

    Now breaking down the 2nd order ode into two 1st order odeBreaking of 2nd order into 2 1st order ode

    Now we have defined θ1 and θ2.

                 ##   Code for solving the 2nd order ode of simple pendulum and simulating it   ##

    % First the code of the function

    function[dtheta_dt] = ode_func(t,theta,b,g,l,m)             % output of the function is dθ/dt
    theta1 = theta(1);                                                       % θ1
    theta2 = theta(2);                                                       % θ2
    dtheta1_dt = theta2;                                                   % dθ1/dt = θ2
    dtheta2_dt = -(b/m)*theta2 -(g/l)*sin(theta1);
    dtheta_dt = [dtheta1_dt;dtheta2_dt];                          % dθ/dt = [dθ1/dt; dθ2/dt]
    end
    
    2nd order ODE func code
     
    % Given values
    % b=0.05
    % g=9.81 m/s^2
    % l=1 m
    % m=1 kg
     
    % Main Code for ode
     
    % Solving 2nd order ode functions
    clear all
    close all
    clc​
     
    % inputs
    b = 0.05;
    g = 9.81;
    l = 1;
    m = 1;​
     
    % initial condition
    % We have two initial conditions, one for angular displacement and one for angular velocity
    theta_0 = [0;3];                    % 0 is for displacment and 3 is for velocity
     
    % time between 0 to 20 sec
    t_span = linspace(0,10,250);
     
    % solving of ode
    % calling the ode45 functions for different values of time (t_span) and initial conditions (theta_0)
    % @(t,theta) refers that the ode function is the function of t and theta
    % ode45 is the inbuilt function which outputs t and result
    % t is times that result is given
    % reslut is output of the function i.,e displacement and velocity 
    % we have angular displacement and angular velocity at times t
    [t,result] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
     
    % Graph
    hold on
    plot(t,result(:,1))
    plot(t,result(:,2))
    xlabel('Time')
    ylabel('Displacement and Velocity')
    legend('Angular displacement','Angular Velocity')​
     
    2nd order ODE code1
     
    % Code for animation of pendulum
    % counter for counting the iteration and saving the frames for the movie in M
    ct = 1;
     
    % creat a for loop from 1 to length of the times of result 
    for i = 1:length(result(:,1))
    % co ordinates for the fixed point of the pendulum
    x0 = 0;
    y0 = 0;
    ​
    % co ordinates for the swinging point of the pendulum fixed to the mass
    x1 = l*sin(result(i,1));
    y1 = -l*cos(result(i,1));​
     
    % stucture of pendulum
    figure(2)
    plot([-5 5],[0 0],'color','k',LineWidth=5)               % fixed support
    axis([-2 2 -1.5 0.5])      % specifying the axis so it does not move for diffrent frames
    
    hold on
    plot([x0 x1],[y0 y1],'color','b')            
    plot(x1,y1,'marker','o','markerfacecolor','r','color','b','markersize',20)
    pause (0.001)
    hold off​
     
    % store all the frames in M by getframe(gct) coomand
    % advance the couter in for loop
    % End the loop
    M(ct) = getframe(gcf);
    ct = ct +1;
    end​
     
    % Creating a movie
    % Make a animated movei of the frames inside of M using movie
    % Use VideoWriter to creat a video file in avi formate
    % open videofile
    % write/insert the frames of M in videofile
    % close videofile
    movie(M)
    videofile_pendulum_oscillation = VideoWriter('videofile_pendulum_oscillation.avi','Uncompressed AVI');
    open(videofile_pendulum_oscillation)
    writeVideo(videofile_pendulum_oscillation,M)
    close(videofile_pendulum_oscillation)​
     
    2nd order ODE code2
     
     
    Result:
     
    Plot is formed of time vs dipalcement and velocity
    2nd order ode plot
     
    Link for the video simulating simple pendulum : https://youtu.be/itR21ANsATo
     
     
     
    Errors faced:
     
    1.  The angle of the pendulum swinging was very small, almost 0. Because, I used sind() and cosd() instead of sin() and cos()errors simple pendulum small angle
     
    2. I used sin for y and cos for x when i had to do the otherwise
    error 2nd order ode sin cos x y

    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 Shaik Faraz (27)

    Project 1 : CFD Meshing for Tesla Cyber Truck

    Objective:

    Aim: Performing topological cleanup and surface mesh on tesla cyber truck and on a wind tunnel based on selected target length values of its different components using element type as Tria, as well as appropriate selection of the volume that contains the vehicle and its surroundings with the wind tunnel for volumetric…

    calendar

    15 Nov 2022 04:17 AM IST

    • ANSA
    • CFD
    Read more

    Week 5 Challenge : Surface wrap on Automotive Assembly

    Objective:

    Aim: Perforform Topo cleanup and delete unwanted surfaces for Surface wrap. After Topo cleanup, Merge all 3 models and perform surface wrap. Target length for Wrap = 3 mm   1. Engine:    2. Gear box:   3. Transmission:   Procedure: 1. Topo Cleanup : (Engine, Transmission & Gear Box)…

    calendar

    10 Nov 2022 08:22 AM IST

      Read more

      Week 4 Challenge : CFD Meshing for BMW car

      Objective:

      Aim: To perform topological clean-up, and carry out the surface meshing of a BMW M6 car model and create a wind tunnel surrounding the same. Objectives: For the given model, check and solve all geometrical errors on half portion and Assign appropriate PIDs. Perform meshing with the given Target length and element Quality…

      calendar

      07 Nov 2022 11:33 AM IST

        Read more

        Week 3 Challenge : CFD meshing on Turbocharger

        Objective:

        Aim: Performing CFD meshing on Turbocharger using ANSA Objective: For the given model, check for the geometrical errors to make appropriate volumes. Create and assign PIDs as shown in the video. Perform surface mesh with the given target lengths as per PIDs. Blade stage-1 = 1 mm Blade stage-2 = 1 mm Impeller = 2 mm…

        calendar

        03 Nov 2022 08:06 AM IST

        • ANSA
        • CFD
        Read more

        Schedule a counselling session

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

        Related Courses

        coursecard

        Design loads considered on bridges

        Recently launched

        10 Hours of Content

        coursecard

        Design of Steel Superstructure in Bridges

        Recently launched

        16 Hours of Content

        coursecard

        Design for Manufacturability (DFM)

        Recently launched

        11 Hours of Content

        coursecard

        CATIA for Medical Product Design

        Recently launched

        5 Hours of Content

        coursecardcoursetype

        Accelerated Career Program in Embedded Systems (On-Campus) Courseware Partner: IT-ITes SSC nasscom

        Recently launched

        0 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.