Project

SOLVING SECOND ORDER ODE

Second Order differential equation : Second order differential equation is a specific type of differential equation that consists of a derivative of a function of order 2 and no other higher-order derivative of the function appears in the equation section.

Examples : Thermodynamics concepts .
Simple pendulum.
calculation of movement of electricity .

AIM :

  • Simple pendulum depends upon the newton's second law.
  • our aim is to define the movement of the pendulum (or) position of the ball w.r.t to time by using initial conditions.
  • The initial conditions be as TIME & DISPLACEMENT.
  • We need create a movie which stores the movement of the pendulum.
  • The given conditions were factors of simple pendulum i.e Mass,Length,Gravity,Damping co-efficient .
    time,angular displacement and velocity .

GOVERNING EQUATIONS :

  • The below differential equation represents the motion of 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.

  • Which is used to define the dynamic behaviour of the system.
  • So , the above equation is called as second order differential equation because its highest order is 2 and to evaluate these type of equations we need to convert into first order differential equation.
  • Finally we can get a array matrix with solution vector which can be solved by matlab .

OBJECTIVE :

  • our aim is to define the movement of the pendulum (or) position of the ball w.r.t to time by using initial conditions.
  • The initial conditions be as TIME & DISPLACEMENT.
  • We need create a movie which stores the movement of the pendulum.
  • The given conditions were factors of simple pendulum i.e Mass,Length,Gravity,Damping co-efficient .
    time,angular displacement and velocity .

  • The above pictures represents the momentum of the pendulum , where we have assumed
    `mgsinpro` as x1sin(theta) & `mgcosprop`as y1cos(theta).

BODY OF THE PROGRAMME :

%A Programme to solve the ODE of simple pendulum and to simulate the motion of pendulum :

%Second_odrer_ode_programm
close all
clear all
clc

%inputs
b = 0.05;
m = 1;
l = 1; 
g = 9.81;

%input_conditions
theta_0 = [0;3];   %intial displacement and intial velocity

%time_points
t_span = linspace(0,20,500);

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

plot(t,results(:,1))
hold on
plot(t,results(:,2)) 
xlabel('time')
ylabel('plot')

%Animation_of_pendulum
displacement = results(:,1);
ct = 1;
for i = 1 : length(displacement)
    angle = displacement(i);
    x0 = 0;
    y0 = 0;
    x1 = 1*sin(angle);
    y1 = -1*cos(angle);
   
    figure(2)
    plot([-1.1 1.1],[0 0],LineWidth=3);
    hold on
    plot([x0 x1],[y0 y1],'linewidth',3)
    
    %plot([x0 x1],[y0 y1],'color','r',LineWidth=3);
    plot(x1,y1,'o','markers',20,'markerfacecolor',[1 1 0]);
    hold off
    grid on
    axis([-1.5 1.5 -1 1])
    pause(0.01)
    M(ct) = getframe(gcf);
    ct=ct+1 ;
end

movie(M)
videofile = VideoWriter('Simple_pendulum.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

ODE_FUNCTION_PROGRAMME :

%A PROGRAMMME OF ODE_FUNCTION :
%Here the mentioned below functional code which can be called to the main programme by 
 using function_inputs.


function[dtheta_dt] = ode_func(t,theta,b,m,g,l)

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

EXPLANATION OF CODE :

  • We have our aim to plot the momentum of pendulum by using the initial condition with the
    second oder differential equation .
  • in the above of the code we have assumed the initial condition which are related to the simple pendulum .
  • Next , the given conditions were angular displacement and velocity , these are solution vectors which were stored in array .
  • we have to simulate the pendulum between the given timespan,so to create that count we will be using the linspace command .
  • [t,results] = ode45(@(t,theta) ode_func(t,theta,b,m,g,l),t_span,theta_0);
  • The above line represents solving ode ,so here we will be using the(t,theta) as dependent variables and using the function followed by the initial conditions .
  • Actually ODE is a in-built solver .
  • Next , the results will be defined which were stored in array by using that we can get a plot as below :

  • But , we need to get a simulated plot of pendulum , for that the rest of the code belongs to it .
  • To simulate the motion , we need store the data in for loop and we need to define the position of
    co-ordinates .
  • After , we ne ed to use hold option so the previous plot will be override.
  • For the next plot we need to use fresh window i.e figure (2) .
  • Finally , we need to plot these values and give the label names & we will be using the counter so the for loop will be executed for multiple times .
  • The counter value will be stored in the array and that stored data will be used to create a movie file to get a smooth simulation .

ODE_FUNCTION EXPLANATION :

  • we have one more code which has mentioned above that means in solving the ODE we have been used the ode_func with the inputs .
  • We willl create a programme regarding the function in the same directary and that code will be called to the main code , so the size of the code will be reduced and code looks good .
  • In the ode function code , we will be creating the programme for the second order differential equations .

CONCLUSION :

  • The solution of the programme will be attached below :

https://drive.google.com/file/d/1Ovx4uc3ILw7UJ73on_03zhoTwY9lcHn7/view?usp=sharing

https://drive.google.com/file/d/1I-EfkJWeAA6DIli52Iy_HQfnHDAvm_Q3/view?usp=sharing

THANK YOU !!

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.