Challenge

Week 3 - Solving second order ODEs

SOLVING SECOND ORDER DIFFERENTIAL EQUATIONS USING MATLAB

AIM: The aim of this project is to solve an ordinary differential equation by using matlab . Particularly in this we are going to solve the equation which describes the ordinary differential equation which describes the motion of simple pendulum .

INTRODUCTION :

As our most of the engineering problems can be solved by using the help of basic and advanced calculus , Ordinary differential equations are also such type of equations which we use to simulate and understand lot of laws and describing and illustrating the various kind of practical problems . An ordinary differential equation is a diffenrential equation containing one or more functions of one independent variables and the derivatives of those functions .As already mentioned , these ordinary differential equations are applicable in variable range of applications , very of the few include in medical industry and etc The foremost example of ordinary differnential equations starts from newtons law of motion . The pendulum is a body suspended from a fixed support so that it swings freely back and forward under the influencce of gravity . The mathematics of simple pendulums are in general quite complicated . Simplifying assumptions can be made , which in this case allow the equations of motion to be solved analyticallly for small range oscilations .

The ordinary differnetial equations have wide applications in varipous engineering and science disciplines . In most particular case the modeling of a varying physical quantities involving constant changges in its magnitude and dirction of The Differential equations have wide applications in various engineering and science disciplines. In general, modeling of the variation of a physical quantity, such as temperature, pressure, displacement, velocity, stress, strain, current,voltage, or concentration of a pollutant, with the change of time or location, or both would result in differentialequations. Similarly, studying the variation of some physical quantities on other physical quantities would also lead to differential equations. In fact, many engineering subjects, such as mechanical vibration or structural dynamics, heat transfer, or theory of electric circuits, are founded on the theory of differential equations. It is practically important for engineers to be able to model physical problems using mathematical equations, and then solve these equations so that the behavior of the systems concerned can be studied.

PRINCIPLE: The simple pendulum or more presicely a simple gravity pendulum is an idealised mathematical model of a simple pendulum . This is a weight on the end on the massless cord suspended from a pivot , without friction . Since in this model there is no frictional energy loss , when given an initial displacement it will swing back and forth at a constant amplitude . The model of this simple pendulum ios based ion some of these kind of assumptions :

  1. The rod or cord on which the bob swing is massless, inextensible , and alwayts remains taut
  2. The bob is point mass
  3. motion occurs only in two dimensions ,ie the bob does not trace an ellipse but an arc
  4. The motion does not loose energy to friction or air resistance
  5. The gravitaional field is uniform
  6. The support doesn't move

the equation which represents the differential equations is given below

PROGRAM :

clear all 
close all 
clc
% inputs 
%damping coefficient 
b = 0.05;
% Gravity 
g = 9.81;
% mass 
m = 1;
% Length of the pendulum in meter
l = 1;
% Initial condition 
t_span = linspace(0,20,200);
theta1= [0;3];

% solving differential equation
[t,results]= ode45(@(t,theta)pendulum_damped_ode(t,theta,l,g,b,m),t_span,theta1)

%plotting 
figure(1)
plot(t,results(:,1))
hold on 
plot(t,results(:,2))
hold on 
grid on 
xlabel('time')
ylabel('angular displacement and angular velocity')
legend('angular displacement','angular velocity')
%animation 
ct=1;
for  i=1:length(results(:,1))
    
    %initial condition
    x0 = 0;
    y0 = 0;
     
    x1 = 1*sin(results(i,1));
    y1 = -1*cos(results(i,1));
    
    figure(2)
    plot([-1 1],[0 0 ],'linewidth',6,'color','g'); %creating beam
    axis([-2 2 -2 2]);%fixed axis 
    line([x0 x1],[y0 y1],'linewidth',2,'color','b');
    hold on;
    plot(x1,y1,'o','markersize',20,'markerfacecolor','r');
    hold off;
    pause (0.1)
    % for animation 
    z(ct) = getframe(gcf);
    ct = ct+1;
end
%Animation 
movie(z)
videofile = videoWriter('pendulum.avi','uncompressed AVI ');
open(videofile)
writeVideo(Videofile,z)
close(videofile)
function[dtheta_dt]= pendulum_damped_ode(t,theta,l,g,b,m)
theta1 = theta(1);%displacemenr
theta2 = theta(2);%veolocity
dtheta1_dt = theta(2);%veolocity 
dtheta2_dt = -(b/m)*theta2-(g/l)*sin(theta1);%acceleration
dtheta_dt =[dtheta1_dt;dtheta2_dt]
end

PLOT :

Animation link:

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

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.