Analytical vs Numerical Methods - A comparison (Explicit Euler Method)
In this project, I will be explaining the explicit 1st order explicit Euler method, its usefulness and its limitations.
For this example, I have assumed the example of a simple ODE, derived from the motion of a spring-mass system,
We know that the ODE depicting this motion is of the form,
`m*((d^2x)/dt^2)+c*(dx/dt)+k*x=0`
From this, we can solve analytically if we assume initial conditions,
Lets say initial displacement = 0 m and initial velocity = 3 m/s,
`x(t)=0.3*e^(-0.005*t)*sin(10*t)`
Now we can use the 1st order explicit Euler formulation to devise an appropriate numerical scheme,
To this to our second order ODE, we first need to convert it into 2 coupled first order ODEs,
To look at the detailed process please look at the following link, where I have explained how to convert a 2nd order ODE into 2 first-order ODEs,
From this, we get the equivalent State Space Vector as shown below,
`s'=[[s1'],[s2']]=[[x'],[x'']]=[[s2],[-(c/m)*s2-(k/m)*s1]]`
We can now write a first order Explicit Euler algorithm to solve these eqauitons,
The code for the Analytical and Numerical Method is shown below using Matlab,
clear all
close all
clc
% Numerical Solution
stp = 0.0001; % step size for the iterative solver
tspan = ((0+stp):stp:5); % time steps to be solved for
vn(1) = 3;
xn(1) = 0;
for i = 2 : length(tspan)
vn(i) = vn(i-1) + stp*(-(0.01*vn(i-1))-(100*xn(i-1)));
xn(i) = xn(i-1) + stp*(vn(i-1));
end
%Analytical Solution
for j = 1 : length(tspan)
xan(j) = 0.3*(exp(-0.005*tspan(j)))*sin(10*tspan(j));
end
%Plotting the results
plot(tspan,xn,'color','blue')
hold on
plot(tspan,xan,'color','red')
xlabel('time [s]')
ylabel('Displacement [m]')
legend('Numerical Solution','Analytical Solution')
Now we can take a look at the results,
For the first case of the result, we make the step size = 0.0001,
we can observe here that the numerical and analytical result both share similar result over the integrated time period
Now let us increase the step size = 0.01 (we increase but a factor of 100),
As we can see here the Numerical Solution Explodes/ Becomes highly unstable.
This is the drawback of the Explicit Euler Methods,
- If we have a stiff ODE system, our solution will explode
- If the time step for a non-stiff ODE system our solution will explode
However, Numerical methods, in general, don't rely on complicated techniques and derivations to solve an ODE hence, any order ODEs and PDEs can both be solved using trivial techniques easily using an appropriate Numerical Scheme
Because of these reasons, we use the implicit Euler method Formulation, However, Implicit Euler method is solver than an Explicit Method.
For my project related to the Implicit Euler and generalised Implicit Euler Solver, Please visit the following links,
Implicit Euler method using Python
https://projects.skill-lync.com/projects/Solving-a-system-of-ODEs-using-Implicit-Euler-method-86502
Generalised Implicit Euler solver using Matlab
https://projects.skill-lync.com/projects/Parametrised-Implicit-1st-order-Euler-Solver-for-ODEs-21951
- Mohammed Abdul MuqeetThe project is really well done. However, The link to the article to convert 2nd order ODE to 2 first-order ODE's is not working.