You are on page 1of 8

REPUBLIQUE TUNISIENE

Minestre de l’Enseignement Superieur


et de la Recherche Scientifique

Ecole Nationale d’Ingénieurs de Gabès

DEPARTEMENT GENIE MECANIQUECLASSE : GM1

Numerical methods with Matlab :

Introduction to Numerical Methods

Done by :

 DAGGARI AMENALLAH
 Chamekh Hazem

Under the supervision of:


- Mr. Wassim Harizi

ANNEE UNIVERSITAIRE
2022/2023
Introduction: ................................................................................................................................................... 3
Common project: ............................................................................................................................................ 3
-Euler Method: ........................................................................................................................................... 3
-Runge-Kutta Method : ............................................................................................................................... 3
Result: ........................................................................................................................................................ 3
The convection-diffusion equation: ................................................................................................................. 4
-initial condition: ........................................................................................................................................ 4
-Forward Euler method: .............................................................................................................................. 5
Crank-Nicolson method: ............................................................................................................................. 6
-convection field: ........................................................................................................................................ 7
Conclusion: .................................................................................................................................................... 8
Introduction:
This work is a project in which we will explore real-world engineering applications of numerical methods,
and creating MATLAB code to implement numerical methods and solve engineering problems.
In this project we will work with two different problems:
• Common project: Numerical solution of ordinary differential equations (ODEs) using Euler’s method
and Runge-Kutta.
• Convection-diffusion equation
Common project:
In the common project we will be solving the following ODE: dydt = −y + sin t

-Euler Method:
The euler method is the most commonly used method for solving ODEs numerically, using this method to
discretize this equation we end up with this approximation:
𝑦𝑖+1 = 𝑦𝑖 + ℎ ∗ (−𝑦𝑖 + sin 𝑡𝑖 )
-Runge-Kutta Method :
The Runge-Kutta method is a fourth order approximation method that can provide more accurate solution
than the euler method using the same step size, using this method to discretize our ODE we end up with the
following approximation:
𝑦𝑖+1 = 𝑦𝑖 + ℎ ∗ (𝐾1 + 2𝐾2 + 2𝐾3 + 𝐾4 )/6
With:
𝐾1 = 𝑦𝑖 + sin 𝑡𝑖
𝐾1 ∗ ℎ ℎ
𝐾2 = − (𝑦𝑖 + ) + sin(𝑡𝑖 + )
2 2

𝐾2 ∗ ℎ ℎ
𝐾3 = − (𝑦𝑖 + ) + sin(𝑡𝑖 + )
2 2
𝐾3 = −(𝑦𝑖 + ℎ ∗ 𝐾3 ) + sin(𝑡𝑖 + ℎ)

Result:
Using the two precedent approximations on our Matlab program we end up with the following result:

Using a step size of 0.1 the result of the two approximations are close but if we use a bigger step size the
result changed as shown in the following figure:

3
Using a step size of 0.5 the difference between the two method is more visible where Euler method shows a
greater defiance then the RK4 method so we can conclude that RK4 method can provide us with more
accurate result weather using small or big step size compared to Euler method.
The convection-diffusion equation:
The convection diffusion equation is a partial differential equation that models the transport of a scalar
quantity such as temperature, concentration or velocity in a fluid or gas, it combines the effects of advection
and diffusion and it can be written as:
∂c
+ ∇ ∙ (vc) = ∇ ∙ (D∇c)
∂t
For the complexity of this equation we based our work on the writing of Jean Donea and Antonio
Huerta "Finite Element Methods for flow problems" in which he used the following approximation:
∆𝑢
+ 𝜃[𝑎∇ − ∇ ∙ (𝑣∇) + σ]∆u = θ𝑠𝑛+1 + (1 − 𝜃)𝑠𝑛 − [𝑎 ∙ ∇ − ∇ ∙ (𝑣∇) + 𝜎]𝑢𝑛
∆𝑡
Note that now second derivatives of u are present due to the diffusion operator. As previously observed in
Section 3.4.1.1, Crank-Nicolson, 6 = 1/2, is the only second-order accurate method. 0 = 1 corresponds to the
implicit backward Euler method, and 8 — 0 is the explicit forward Euler method. For 9 > 1/2, the scheme is
A-stable. Usually, the Crank-Nicolson scheme is used for true transient problems where time accuracy is
important. The backward Euler or the so-called0 Galerkin scheme, 0 = 2/3, may be used to obtain steady-state
solutions by means of a timemarching approach with large time steps (usually called relaxation methods).

-initial condition:
The initial condition is defined by the following equation:
1 𝑥 − 𝑥0
𝑢0 = ∗ (1 + cos (𝜋 ∗ )) ∗ (1
4 𝑟
𝑦 − 𝑦0
+ cos(𝜋 ∗ )) ∗ 𝐻((𝑥 − (𝑥0 − √𝑟 2 − (𝑦 − 𝑦0 )2 )) ∗ 𝐻((𝑦 − (𝑦0 − √𝑟 2 − (𝑥 − 𝑥0 )2 ))
𝑟
∗ (1 − 𝐻(𝑥 − ( (𝑥 − (𝑥0 − √𝑟 2 − (𝑦 − 𝑦0 )2 ))) ∗ (1 − 𝐻((𝑦 − (𝑦0 − √𝑟 2 − (𝑥 − 𝑥0 )2 )))
1
With: 𝑥0 = 5 ; 𝑦0 = 1/5.
And the boundary condition is null, and r present the radius which present the radius of the hill and H present
the function heavieside.
1 1 1 1 𝜋
We chose a grid of 30 by 30 aand a length of 1 by 1 where 𝑥𝜖 [− 2 ; 2] ; 𝑦𝜖 [− 2 ; 2], and a time step of ∆𝑡 = 500
We chose the source term to be 2 and the diffusion coefficient to be 0.01.
4
the initial condition are shown as fellow:

-Forward Euler method:


Using forward euler method we obtained this result: for a source value of 2

5
If we change the source term to 0 the result and the initial condition results change as fellow:

Crank-Nicolson method:
The result of the Crank-Nicolson approximation shows a very similar result for a source term equal to 2::

6
If we change the source term to 0 the result became as follow:

-convection field:
The convection field is determined as fellows:

7
Conclusion:
We note that this equation has a lot of variables and the result can easily change by changing any variable. In
our case the result was very close in both approximation (Euler and Crank-Nicolson method), when
comparing our result with others in the web we remark some differences that can be explained by the different
approximation method or the different conditions used. The program includes two more approximation
method “Backward Euler” and “Galerkin” methods for more result example and comparison, generally the
four different methods used in this simulation behave almost the same way as each other thatr’s why we only
showed two of the results in our report.

N.B: we can control the source term in line 22 of the main program and we can controle the speed of the
animation by changing the animation time in line 36 of the program. We can change the approximation
method in line number 44 of the program; the program comes with animation of the solution.

You might also like