<h1><center> Computation of the modified equation of a numerical scheme (univariate PDE evolution equation)</center></h1>
<center>
    Olivier Pannekoucke <br> 2020

# Introduction

In this illustration we compute the modified equation assowiated with the Euler discretization and the centered discretization of the advection equation
$$(1)\quad \partial_t u + c \partial_x u =0$$
whose numerical scheme is 
$$(2)\quad u^{q+1}_k =  u_k^q - c \delta t \frac{u^q_{k+1}-u^q_{k-1}}{2\delta x}$$
where $u^q_k$ stands for a numerical approximation of $u(q\delta t,k\delta x)$.

## Application to the Euler time scheme applied on the advection

#### Import of modules & functions


```python
from modequation import ModifiedEquation
import sympy
from sympy import symbols, Derivative, Function, Eq
```


```python
c = sympy.symbols('c')
coordinates = sympy.symbols('t x')
t, x = coordinates
dt, dx = sympy.symbols('dt dx')

u = Function('u')(*coordinates)
```


```python
u_qp=u.subs(t,t+dt)
u_kp=u.subs(x,x+dx)
u_km=u.subs(x,x-dx)
```

#### Definition of the time schemes

First we define the numerical schemes as an equation (`sympy.Eq`)
$$(3)\quad \frac{u^{q+1}_k-u_k^q }{\delta t} =  - c \frac{u^q_{k+1}-u^q_{k-1}}{2\delta x}$$



```python
euler_centered_scheme = Eq( (u_qp-u)/dt, -c * (u_kp-u_km)/(2*dx))
```

#### Computation of the modified equations


```python
euler_centered = ModifiedEquation(euler_centered_scheme,u, order =3)
```


```python
euler_centered.consistant_equation
```




$\displaystyle \frac{\partial}{\partial t} u{\left(t,x \right)} = - c \frac{\partial}{\partial x} u{\left(t,x \right)}$




```python
euler_centered.modified_equation
```




$\displaystyle \frac{\partial}{\partial t} u{\left(t,x \right)} = - c \frac{\partial}{\partial x} u{\left(t,x \right)} - \frac{c dx^{2} \frac{\partial^{3}}{\partial x^{3}} u{\left(t,x \right)}}{6} - \frac{c^{2} dt \frac{\partial^{2}}{\partial x^{2}} u{\left(t,x \right)}}{2} + O\left(dx^{3}\right) + O\left(dt^{3}\right)$



b7a5068b3b2b37714893bc47f872d9628bd04b1e
ipynb
Jupyter Notebook
euler-centered-modified-equation.ipynb
opannekoucke/modified-equation
11a0f18b24e3142a65976048e385e9def54628fd
CECILL-B
euler-centered-modified-equation.ipynb
opannekoucke/modified-equation
11a0f18b24e3142a65976048e385e9def54628fd
CECILL-B
euler-centered-modified-equation.ipynb
opannekoucke/modified-equation
11a0f18b24e3142a65976048e385e9def54628fd
CECILL-B
Qwen/Qwen-72B
1. YES
2. YES