MATLAB Program - To Solve Differential Equation Using Euler’s Method

Using Euler's method to solve differential equation

Can you imagine a point where we do not use differential equation to solve differential condition?

Truth be told, there are a few different ways of tackling differential conditions, yet once in a while even these techniques which you will learn in future exercises will now and then will be too hard to even consider settling by hand.

Question: Is there a technique for tackling differential conditions when you are given a condition, that will work when different strategies?

Answer: yes, its Euler's Method!

What is Euler’s technique?

Euler's technique is utilized for approximating answers for certain differential conditions and works by approximating an answer with line segment.

Uses of Euler’s technique:

Euler's technique is helpful in subjects like physics, economics, mathematics, and chemistry since differential equations appear frequently in them, but difficult to solve them directly (or explicitly), so we try to find their solutions approximately.

For instance, Euler's technique can be utilized to find solution approximately like the path of any moving or falling object through a fluid(viscous in nature), over the time the rate of a reaction, the traffic flow on a busy schedule road, and many more examples of real life.

Program explanation:

Euler's technique is helpful since differential conditions show up regularly in material science, scientific areas, and financial matters, however generally can't be tackled easily, requiring their answers for be approximated.

For Example let’s discuss LC circuit.

LC CIRCUIT   

LC circuit is an electronic circuit which consists an inductor (the letter L represents inductor), and a capacitor (the letter C represents capacitor), all are connected together.

Roles played by the circuit are:

  • electrical resonator,
  • tuning fork electrical analogue ,
  • for capturing all energy at the circuit's resonate frequency.

Basic steps to help you get started with the problem.

Step1:

The equation for LC circuit network à dI1 / dt = I1 *

Step2:

From network to the program mapping with the equations:

I2 = I1*

Step 3:

Consider the only value initial of i as 3 and performing 60 iterations to find solution of the equation.

Code is explained with the help of comments as follows:

i= 3; 
iter = 60 ;
dt = 0.1 ;  % Delta t as Step Size
I2 = zeros( iter  , 1) ; % this vector i is initialized to being all zeros
t1 = zeros( iter ,1) ;
i( 1 ) = I0 ; % the  condition is set
t1( 1 ) = 0.0 ;
for step = 1 : iter - 1 % Performing all iterations
i(step + 1)  = i( step ) + dt * ( I ( step) ) ;
t1(step + 1) = t1(step) + dt;
end
% here there is a temporary end of the section, next we will start plotting the results by using %a graph
i
plot(t1, I , 'b' ) ; % Plotting the result
% here title is set as “ Sol of 1st Differential Equation ”
title( ' Sol of 1st Differential Equation')
xlabel(' label Time')
ylabel(' label Current')
hold on; 
Iini= 1; % Initial value of I
I1 = zeros( iter, 1 ) ; 
T1 = zeros (iter , 1 ) ;
I1(1) = Iini; % the initial condition is initialized
T1(1) = 0.0;
for step = 1 : iter – 1  % Performing all iterations
I1(step + 1) = I1(step) – dt * ( I1(step));
T1(step + 1) = t1( step ) + dt;
end
I1 
plot(t1 , I1 , 'r' ) ; 
% here title is set as “ Sol of 1st Differential Equation ”
title( ' Sol of 1st Differential Equation')
xlabel('label Time')
ylabel('label Current')
hold on; 

Output:

i =
    2.0000   2.2000  2.4200  2.662   2.9282  3.2210  3.5431  3.8974   4.287  4.7159  5.1875  5.7062 0.2059  0.1853  0.0108  0.0097 0.0087 6.2769  74.8087   82.2896 120.4801   0.2059   0.1853   0.0108   0.0097    0.0087  132.5282 145.7810  160.3591  176.3950  194.034 213.4379
I1 =
    1.0000  0.9000    0.8100    0.7290    5.187    5.7062    6.2769   74.8087   82.2896  120.4801    0.656    0.5905    0.5314    0.4783    0.4305   0.3874    0.3487    0.2059    0.1853    0.0108    0.0097    0.0087     0.2059    0.1853    0.0108
MATLAB Program - To Solve Differential Equation Using Euler's Method



ADVERTISEMENT
ADVERTISEMENT