# Heat equation order of accuracy (Crank-Nicolson)

Tags:
1. Jun 2, 2015

### pomekrank

Hi,

Let's consider the heat equation as $\frac{\partial T}{\partial t}=\alpha \frac{{{\partial }^{2}}T}{\partial {{x}^{2}}}$

In order to have a second accuracy system, one can use the Crank-Nicolson method as $\frac{{{\partial }^{2}}T}{\partial {{x}^{2}}}\approx \frac{1}{2}\left( \frac{T_{i+1}^{k+1}-2T_{i}^{k+1}+T_{i-1}^{k+1}}{\Delta {{x}^{2}}}+\frac{T_{i+1}^{k}-2T_{i}^{k}+T_{i-1}^{k}}{\Delta {{x}^{2}}} \right)+O\left( \Delta {{t}^{2}}+\Delta {{x}^{2}} \right)$

However, when the finite difference method is use with respect to time, usually a forward Euler method like $\frac{\partial T}{\partial t}\approx \frac{T_{i}^{k+1}-T_{i}^{k}}{\Delta t}+O\left( \Delta t,\,\,\Delta x \right)$

Does it make the entire system an accuracy $O\left( \Delta t,\Delta {{x}} \right)$ ? If so, why don't use a much simpler method like center difference $\frac{\partial T}{\partial x}\approx \frac{T_{i+1}^{k}-T_{i-1}^{k}}{2\Delta x}+O\left( \Delta t,\,\Delta {{x}^{2}} \right)$ instead of Crank-Nicolson ? Furthermore, if one wants to get a full 2nd order system, how could it be possible ?

Thank you,
Steven

2. Jun 3, 2015

### theodoros.mihos

I use central difference on $\partial/\partial{t}$ but the stability condition stays the same. If you see the factors for $T$, for $\Delta{t}$ larger than a limit, equation for $T_{i+1}$ give value raising up only.

3. Jun 3, 2015

### the_wolfman

You are wrongly attributing aspects of the temporal discretization them to the spatial discretization. And I think this is why you're confused.

Crank-Nicolson uses the temporal discretization: $\frac{T_i^{n+1}-T_i^n}{\Delta t}=\alpha \frac{1}{2}\left(\frac{\partial^2 T^{n+1}}{\partial x^2}+\frac{\partial^2 T^{n}}{\partial x^2}\right)$

This step is determines that the accuracy in $\Delta t$ is second order. There are two things to note. First, we have not yet discretized the spatial derivative. Second, a important part of this temporal discretization is that we average the right side of the equation over the n and the n+1 time step.

The spatial discritization determines the accuracy in $\Delta x$. Crank-Nicolson uses center difference, which is second order accurate, to approximate the spatial derivative: $\frac{\partial^2 T}{\partial x^2}\approx \frac{T_{i+1}-2T_i+T_{i-1}}{2\left(\Delta x\right)^2}$.

Note that time doesn't even enter this approximation.

As a general rule, changing the temporal discretization alters the accuracy in $\Delta t$, and changing the spatial discretization alters the accuracy in $\Delta x$.

4. Jun 3, 2015

### pomekrank

Ok if I do understand, Crank-Nicolson's order in space depends on how you approximate the spatial derivative and temporal is by definition an order of 2 because it's averaged. In my case it's true to say that C-N is O(Δt^2, Δx^2), but irrelevant to say that the order in the left side of the equation (dT/dt) is dependant of Δx.

However, there's still some facts that I need to get straight.
1- Why use C-N method over a simple centered spatial discretisation if center difference is also O(Δx^2)
2- Is it a good idea to increase the order of accuracy over decreasing the time/space step size ? In my case I would like to have a quadratic order for time and space. How would it affect stability and convergence speed ?

Thank you,
Steven

5. Jun 8, 2015

...

6. Jun 9, 2015

### the_wolfman

The temporal advance is 2nd order because that's what the math shows it to be. It's not a definition. There are multiple ways to "average" the RHS, and they will give you different orders of accuracy. Do you know how to calculate the accuracy of an approximation using Taylor series?

I'm not sure I understand your point. C-N uses the standard centered difference to approximate the spatial derivative. One of the main advantages of C-N is that it is unconditionally stable.

Again, I'm don't understand you question. C-N is second order (quadratic) in space and time. It is also unconditionally stable.

Are you asking about methods that are cubic, quartic, or higher order accurate? There are a number of trade-offs to using higher order methods. Higher order methods can have more restrictive stability limits. The algebraic systems that result are harder to solve. Some problems benifit greatly form using higher order methods, while other problems see little benefit.

7. Jun 9, 2015

### Strum

The C-N method is unconditionally stable for the diffusion equation. This means that criterions like $\Delta t < \Delta x^{2}$ does not have to be obeyed.

Just to make matters more confusing, as far as wiki goes C-N is only the implicit time discretization. The spatial you are free to choose.

8. Jun 9, 2015

### pomekrank

Ok I get the fact that CN is unconditionally stable, but If i can reword my question to make it as easy as possible, if the left side is

(1) $\frac{\partial T}{\partial t}\approx \frac{T_{i}^{k+1}-T_{i}^{k}}{\Delta t}+O\left( \Delta t \right)$
or
(2) $\frac{\partial T}{\partial t}\approx \frac{3T_{i}^{k}-4T_{i}^{k-1}+T_{i}^{k-2}}{2\Delta t}+O\left( \Delta {{t}^{2}} \right)$

Using the same heat equation with CN method for estimating $\frac{{{\partial }^{2}}T}{\partial {{x}^{2}}}$.

Will (2) improve the accuracy of the system and the stability ?

The thing I didn't undestand in the first place was why to use (1) with CN since they have different order of accuracy. In this case, using (2) with CN should be better because we stay with all equation of order Δt^2.

9. Jun 9, 2015

### the_wolfman

There are 2 parts to the temporal discretization of CN. The first part is the discretization of the time derivative. The second part is the time discretization of the right side of the equation. The accuracy and stability of the CN method depends on the specific choice of both discretization.
There is a cancellation that occurs because CN picks a clever discretization of the right side of the equation. This cancelation allows CN to be 2nd accurate in time. You will never see cancellation if you ignore the temporal discretization of the right side of the equation.

Do you know how to evaluate the accuracy and stability of a finite difference method applied to a particular ODE? I do not know offhand what will happen if you use equation (2) to approximate the time derivate. I suspect that you will not see a significant difference in the accuracy of the two methods. I hesitate to comment on the stability, but there's a chance that the stability is worse using equation (2) than it is using equation (1).

10. Jun 9, 2015

### pomekrank

Does CN is ONLY good with heat equation or it's still reliable for similar equation like
$\frac{\partial T}{\partial t}=\alpha \frac{{{\partial }^{2}}T}{\partial {{x}^{2}}}+\beta \frac{\partial T}{\partial x}$

11. Jun 10, 2015

### Megna

12. Jun 11, 2015

### Strum

Well C-N is just an implicit solution method. I would imagine you could use it on pretty much any equation you like. For linear equations the implementation is fairly simple as well. Here is the wiki page about the solution of that equation
http://en.wikipedia.org/wiki/Numerical_solution_of_the_convection–diffusion_equation

Also for a more general framework you could look up operator splitting methods of which C-N is just a specific case.

13. Jun 13, 2015

### theodoros.mihos

If you want bypass linear systems, you can use shooting methods starting from both bounds and ask same value and same 1st derivative on a meeting point. RK4 and Numerov algorithm works fine. For Scrodinger equation I use Numerov with 1% error area. It is faster and simpler than RK4.
See this result

Last edited: Jun 13, 2015