Week 3 - Solving second order ODEs
https://drive.google.com/file/d/1bybTMojYuOkonhWyf7bNPPVgCnR9h756/view?usp=sharing
https://drive.google.com/file/d/1bybTMojYuOkonhWyf7bNPPVgCnR9h756/view?usp=sharing
ODE
An ordinary differential equation (also abbreviated as ODE), in Mathematics, is an equation which consists of one or more functions of one independent
variable along with their derivatives. A differential equation is an equation that contains a function with one or more derivatives. But in the case ODE,
the word ordinary is used for derivative of the functions for the single independent variable.
First Order Differential Equation
You can see in the first example, it is a first-order differential equation which has degree equal to 1. All the linear equations in the form of derivatives are in the first order. It has only the first derivative such as dy/dx, where x and y are the two variables and is represented as:
dy/dx = f(x, y) = y’
Second-Order Differential Equation
The equation which includes the second-order derivative is the second-order differential equation. It is represented as;
d/dx(dy/dx) = d2y/dx2 = f”(x) = y”
Applications
Differential equations have several applications in different fields such as applied mathematics, science, and engineering. Apart from the technical applications, they are also used in solving many real life problems. Let us see some differential equation applications in real-time.
1) Differential equations describe various exponential growths and decays.
2) They are also used to describe the change in return on investment over time.
3) They are used in the field of medical science for modelling cancer growth or the spread of disease in the body.
4) Movement of electricity can also be described with the help of it.
5) They help economists in finding optimum investment strategies.
6) The motion of waves or a pendulum can also be described using these equations.
The various other applications in engineering are: heat conduction analysis, in physics it can be used to understand the motion of waves. The ordinary differential equation can be utilized as an application in the engineering field for finding the relationship between various parts of the bridge.
Now, go through the differential equations examples in real-life applications .
simple pendulum
A simple pendulum can be described as a device where its point mass is attached to a light inextensible string and suspended from a fixed support.
The vertical line passing through the fixed support is the mean position of a simple pendulum. The vertical distance between the point of suspension and
the centre of mass of the suspended body (when it is in mean position) is called the length of the simple pendulum denoted by L.
This form of the pendulum is based on the resonant system having a single resonant frequency.
Important Terms
The oscillatory motion of a simple pendulum:
Oscillatory motion is defined as the to and fro motion of the pendulum in a periodic fashion and the centre point of oscillation known as equilibrium position.
The time period of a simple pendulum: It is defined as the time taken by the pendulum to finish one full oscillation and is denoted by “T”.
The amplitude of simple pendulum: It is defined as the distance travelled by the pendulum from the equilibrium position to one side.
Length of a simple pendulum: It is defined as the distance between the point of suspension to the centre of the bob and is denoted by “l”.
solution for solving 2 order ODE equation of motion of a simple pendulum with damping.
d^2θ/dt^2+(b/m)(dθ/dt)+(g/L)sinθ=0
g = 9.81; %Accleration due to gravity
L = 1; %Length of string in m
m = 1; %Mass in kg
b = 0.05; %Damping coefficient
we have to convert 2order ODE to first order ODE beacuse ODE45 only solves first order equation.
i have modified the equation to solve it more easily
d^2x/dt^2+(b/m)(dx/dt)+(g/L)sinθ=0
using state vector approach
{xdot}={A}{x}+{B} (for explaination purpose)
where{x}=state vector and also x is column vector of size n
{x}={x1;x2;....xn}={x;dx/dt;d^2x/dt;....d^(n-1)x/dt} it is in column i.e. i have used semicolon to separate them
xdot=x2
x2=x3
.....xn-1=xn
xdot(1)=dx1/dt=dx/dt=x2
xdot(2)=-(g/L)*sin(x(1))-(b/m)*x(2);
%to solve a program in Matlab that will simulate the pendulum motion
%time span of pendulum
t = linspace(0,20,500);
%x0 has two values, first one is initial condition for angular displacment and second one is for angular velcity
x0 = [0;5];
[t, x] = ode45('ode_func',t,x0);%ode45 is a ODE solver.
plot(t,x(:,1))%to plot the angular displacement
hold on
plot(t,x(:,2))%to plot the angular velocity
ylabel('plot') %for labeling the y axis
xlabel('time')%for labeling the x axis
%animation_code
%for loop being used for capturing each time interval
for i=1:length(t)
L = 1;
X0=0;
Y0=0;
%to calculate the co-ordinates of bob at time t
X1 = L* sin(x(i));
Y1 = -L* cos(x(i));
%making a fixed plane
figure(2);
plot([-1 1],[0 0],'LineWidth',2,'color','black');%linewidth for giving the value to the width of line and used color for colouring to our need
hold on
%string of pendulum
plot([0 X1],[0 Y1],'LineWidth',2,'color','b');%linewidth for giving the value to the width of line and used color for colouring to our need
hold on
%to plot the bob at different time interval
%used the marker command for making the bob and used markersize and
%markerfacecolor to modify the bob according to our need
plot(X1,Y1,'o','markersize',20,'markerfacecolor','black');
grid on
axis([-2 2 -2 1]) %to specify the axis inside which the entire system will move
pause(0.001); %to pause execution for given time before continuing
hold off
F(i) = getframe(gcf); %to captures the current axes
end
%to write video data to an AVI file
video = VideoWriter('pendulum.avi','Uncompressed AVI');
video.FrameRate = 60; %frame rate
open(video) %to open the videofile
writeVideo(video,F);%to write data from an array to the video file associated with video
close(video) %to close the video
%the function code
function [xdot] = ode_func(t,x)
g = 9.81; %Accleration due to gravity
L = 1; %Length of string in m
m = 1; %Mass in kg
b = 0.05; %Damping coefficient
xdot = zeros(2,1);
%angular displacement
xdot(1) = x(2);
%angular velocity
xdot(2) = -(g/L)*sin(x(1))-(b/m)*x(2);
end