How to calculate the centered approximation of ${\frac{{df}}{{dt}} = - \frac{f}{\tau }}$?

59 Views Asked by At

In the textbook of An Introduction to Computational Methods in Hydrodynamics by Willy Benz. 2.2 Differential Equations.

enter image description here

I know how to derive the general formula above $$ f\left( {{x_0} + \Delta x} \right) = f\left( {{x_0}} \right) + {\left( {\frac{{\partial f}}{{\partial x}}} \right)_{{x_0}}}\Delta x + \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_{{x_0}}}\Delta {x^2} + O\left( {\Delta {x^3}} \right) $$ $$ f_{k + 1}^n = f_k^n + {\left( {\frac{{\partial f}}{{\partial x}}} \right)_k}\Delta x_{k + \frac{1}{2}}^n + \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_k}{\left( {\Delta x_{k + \frac{1}{2}}^n} \right)^2} + O\left( {\Delta {x^3}} \right) $$

-- $$ f\left( {{x_0} - \Delta x} \right) = f\left( {{x_0}} \right) + {\left( {\frac{{\partial f}}{{\partial x}}} \right)_{{x_0}}}\left( { - \Delta x} \right) + \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_{{x_0}}}{\left( { - \Delta x} \right)^2} + O\left( {{{\left( { - \Delta x} \right)}^3}} \right) $$ $$ f_{k - 1}^n = f_k^n + {\left( {\frac{{\partial f}}{{\partial x}}} \right)_k}\Delta x_{k - \frac{1}{2}}^n + \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_k}{\left( {\Delta x_{k - \frac{1}{2}}^n} \right)^2} + O\left( {{{\left( {\Delta x} \right)}^3}} \right) $$

-- $$ f_{k + 1}^n - f_{k - 1}^n = {\left( {\frac{{\partial f}}{{\partial x}}} \right)_k}\left( {\Delta x_{k + \frac{1}{2}}^n - \Delta x_{k - \frac{1}{2}}^n} \right) + \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_k}\left( {{{\left( {\Delta x_{k + \frac{1}{2}}^n} \right)}^2} - {{\left( {\Delta x_{k - \frac{1}{2}}^n} \right)}^2}} \right) + O\left( {\Delta {x^3}} \right){\text{ }} $$ $$ {\left( {\frac{{\partial f}}{{\partial x}}} \right)_k} = \frac{{f_{k + 1}^n - f_{k - 1}^n}}{{2 \cdot \Delta {x_k}}} - \frac{1}{2}{\left( {\frac{{{\partial ^2}f}}{{\partial {x^2}}}} \right)_k}\frac{{\left( {{{\left( {\Delta x_{k + \frac{1}{2}}^n} \right)}^2} - {{\left( {\Delta x_{k - \frac{1}{2}}^n} \right)}^2}} \right)}}{{2 \cdot \Delta {x_k}}} + O\left( {\Delta {x^2}} \right) $$


But I am stuck below:

given ${\frac{{df}}{{dt}} = - \frac{f}{\tau }}$ & $f(0)=1$

I know how to get these 2,

$$ \begin{array}{l} \left[ {{\text{forward difference approximation}}} \right]\\ \frac{{\delta f}}{{\delta t}} \equiv \frac{{{f^{n + 1}} - {f^n}}}{{\Delta t}}\\ - \frac{1}{\tau } \cdot f\left( {{t_0}} \right) \approx \frac{{f\left( {{t_0} + \Delta t} \right) - f\left( {{t_0}} \right)}}{{\Delta t}} \end{array} $$ $$ \begin{array}{l} \left[ {{\text{backward difference approximation}}} \right]\\ \frac{{\delta f}}{{\delta t}} \equiv \frac{{{f^n} - {f^{n - 1}}}}{{\Delta t}}\\ - \frac{1}{\tau } \cdot f\left( {{t_0}} \right) \approx \frac{{f\left( {{t_0}} \right) - f\left( {{t_0} - \Delta t} \right)}}{{\Delta t}} \end{array} $$

but how can you get the centered approximation of the given function as following?

and how can you get numerical solutions of it?

$$ \frac{{{f^{n + 1}} - {f^n}}}{{\Delta t}} = - \frac{1}{{2\tau }}\left( {{f^{n + 1}} + {f^n}} \right) $$ $$ \frac{{f\left( {{t_0} + \Delta t} \right) - f\left( {{t_0}} \right)}}{{\Delta t}} = - \frac{1}{{2\tau }} \cdot \left( {f\left( {{t_0} + \Delta t} \right) + f\left( {{t_0}} \right)} \right) $$ enter image description here

Following is the graph for a better visualization of the solutions at different time points. enter image description here


Update 20210201_174816

$$ \begin{array}{l} \frac{{{f^{n + 1}} - {f^n}}}{{\Delta t}} = - \frac{1}{\tau } \cdot \frac{{{f^{n + 1}} + {f^n}}}{2}\\ \frac{{{f^{n + 1}} - {f^n}}}{{\Delta t}} = - \frac{1}{{2\tau }}\left( {{f^{n + 1}} + {f^n}} \right)\\ {f^{n + 1}} - {f^n} = - \frac{{\Delta t}}{{2\tau }}\left( {{f^{n + 1}} + {f^n}} \right)\\ set:\left\{ {\alpha = \Delta t/\tau } \right.\\ {f^{n + 1}} - {f^n} = - \frac{\alpha }{2}\left( {{f^{n + 1}} + {f^n}} \right)\\ \left( {1 + \frac{\alpha }{2}} \right){f^{n + 1}} = {f^n} \cdot \left( {1 - \frac{\alpha }{2}} \right)\\ {f^{n + 1}} = \frac{{\left( {1 - \frac{\alpha }{2}} \right)}}{{\left( {1 + \frac{\alpha }{2}} \right)}}{f^n}\\ given:\left\{ {\alpha = \Delta t/\tau = 0.2} \right.\\ {f^{n + 1}} = \frac{{\left( {1 - \frac{{0.2}}{2}} \right)}}{{\left( {1 + \frac{{0.2}}{2}} \right)}}{f^n}\\ {f^n} = {\left( {\frac{{\left( {1 - \frac{{0.2}}{2}} \right)}}{{\left( {1 + \frac{{0.2}}{2}} \right)}}} \right)^n} \cdot f\left( 0 \right) = {\left( {\frac{{\left( {2 - 0.2} \right)}}{{\left( {2 + 0.2} \right)}}} \right)^n} \cdot 1\\ {f^{2\tau /0.2\tau }} = {\left( {\frac{{\left( {2 - 0.2} \right)}}{{\left( {2 + 0.2} \right)}}} \right)^{10}} = 0.134430632749 \end{array} $$

Above does not match with the textbook, which is 0.1407.

1

There are 1 best solutions below

7
On

The comment right below Eq. (2.2.4) is giving you a clue

Notice that (2.2.4) has been centered in a somewhat surprising way. Using a straightforward analog of (2.1.9) for estimating the time derivative of $f$ would lead to an intrinsically unstable and therefore useless numerical scheme.

Apparently that is further discussed in section 3, but I can give you an argument here.

How NOT to do it

If you stick to Eq. (2.1.9) you end up with

$$ \frac{f^{(n+1)} - f^{(n-1)}}{2\Delta t} = -\frac{f(\text{where should I evaluate this?})}{\tau} \tag{1} $$

the problem is that if you decide evaluate the right hand side (RHS) at $t^{(n)}$ then you will two initial conditions to solve the iteration. A better approach is to evaluate in the average of the points of the grid

$$ \frac{f^{(n+1)} - f^{(n-1)}}{2\Delta t} = -\frac{f^{(n+1)} + f^{(n-1)}}{2\tau} \tag{2} $$

which can be expressed as

$$ f^{(n+1)} = \frac{1 - \alpha}{1 + \alpha} f^{(n-1)} ~~~\alpha= \frac{\Delta t}{\tau} \tag{3} $$

and the issue with this one is that you end up with parallel tracks for even/odd indices.

HOW TO DO IT

Use forward difference on the derivative, and evaluate the RHS on the average of the grid

$$ \underbrace{\frac{f^{(n+1)} - f^{(n)}}{\Delta t}}_{\text{forward}} = -\frac{1}{\tau}\underbrace{\frac{f^{(n+1)} + f^{(n)}}{2}}_{\text{average point}} \tag{4} $$

Rearranging a bit

$$ f^{(n+1)} = \frac{2 - \alpha}{2 + \alpha} f^{(n)} \tag{5} $$

whose solution is

$$ f^{(n)} = \left(\frac{2 - \alpha}{2 + \alpha} \right)^n f^{(0)} \tag{6} $$

EDIT 20210203

These are the solutions for all the methods

\begin{eqnarray} f_{\rm forward}^{(n)} &=& (1 - \alpha)^n f^{(0)} \\ f_{\rm backward}^{(n)} &=& \left(\frac{1}{1 + \alpha}\right)^n f^{(0)} \\ f_{\rm centered}^{(n)} &=& \left(\frac{2 - \alpha}{2 + \alpha}\right)^n f^{(0)} \end{eqnarray}

and in graphical form

enter image description here

You can see that lines are in a different order in the picture you posted ... I'm leaning towards a problem with the book