Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Approximations used in Crank-Nicolson method for solving PDEs numerically

  1. Sep 2, 2009 #1
    Hi all,

    A diffusion equation is of the form
    [tex]\frac{\partial u}{\partial t}=k \frac{\partial^2u}{\partial x^2}[/tex]

    Usually an equation like this seems to be solved numerically using the Crank-Nicolson method:
    [tex]\frac{u_{i}^{n + 1} - u_{i}^{n}}{\Delta t} = \frac{k}{2 (\Delta x)^2}\left((u_{i + 1}^{n + 1} - 2 u_{i}^{n + 1} + u_{i - 1}^{n + 1}) + (u_{i + 1}^{n} - 2 u_{i}^{n} + u_{i - 1}^{n})\right)[/tex]

    i.e the time-related part is approximated using a 2-point forward difference approximation and the space-part using an average of two 3-point central difference approximation. ([tex]u_{i}^{n}[/tex] means value of u at point i at timestep n, i.e u(i,n))

    Is there a specific reason why a central difference is not used for the time? Since a central difference results in a smaller error, yet it's not usually used, what drawback does it have?

    What about the central difference for the space-related part? Is there a reason for using the 3-point version instead of the 5-point version? Or is the simpler one usually used because it results in a tridiagonal matrix which is easier to solve?

    edit: Clarified notation
    Last edited: Sep 2, 2009
  2. jcsd
  3. Sep 2, 2009 #2
    I don't know anything about this method but How would know what the value is in the future time step before the derivative was estimated? (I think though Rung Kutta Methods for ODE's try and do what you suggest).
  4. Sep 2, 2009 #3
    I was unclear. The point is that I wish to know the value of [tex]u[/tex] at the next time step at every point, solving the mentioned equation for [tex]u_{i}^{n + 1}[/tex] for each [tex]i[/tex] (requires solving a set of linear equations) tells me just that.
  5. Sep 2, 2009 #4
    In that case I'm surprised you have enough equations given it looks like there will be at least two unknowns per equation. However, I suppose you use an integration step to get that other unknown.
  6. Sep 2, 2009 #5
    No, number of unknowns is not a problem.

    Assuming [tex]u[/tex] is defined at m [tex]m[/tex] points (it has been discretized) we obviously end up with [tex]m[/tex] unknowns: [tex]u_i^{n+i}, 1 \leq i \leq m[/tex].
    We get [tex]m-2[/tex] equations by plugging in [tex]i=2,3,4,...,m-1[/tex] into the equation in the original post. Plugging in [tex]i=1[/tex] doesn't work because [tex]u_{0}^{n+1}[/tex] required by the approximation isn't defined. Similarly you can't plug in the value [tex]i=m[/tex] because [tex]u_{m+1}^{n+1}[/tex] isn't defined.

    Is all hope lost? No, because if we additionally specify two boundary conditions (say [tex]u_0^{n+1}=0[/tex] and [tex]u_m^{n+1}=0[/tex]) we end up with the required [tex]m[/tex] equations and the system has a unique solution.

    There is no question this method doesn't work. My specific problem was with some of the details, why certain approximations are used instead of others that should result in more accurate results.
  7. Sep 2, 2009 #6
    I should have realized that. Anyway, if you wanted to do the central difference for the derivative, you would also need [tex]u_{i}^{n+2}[/tex] if you didn't want to introduce any time legs. This means you would need twice as many equations. This would obviously slow down your algorithm but it might help accuracy.
  8. Sep 13, 2009 #7
    Yes, there is a reason. It would be unstable. A quick way to check. The instability mode is usually an alternating wave, +-+-+-+.... It will be modified by a factor h say in each step. Substitute that in the algorithm - ie in successive timesteps, (+1,-1,+1...), (+h,-h,+h..), (+h^2,-h^2,+h^2..).
    For a two-step algorithm like C-N, you'll get a linear equation for h, which will be <1. The wave decays, which is what you want and expect.
    For a three-step algorithm like the one you propose, you'll get a quadratic in h. You'll quickly see that the product of the roots is 1. One is less than 1, and is also the one you expect. In fact, it's more accurate than C-N. But there is a spurious second root that is greater than 1. That causes such waves to grow exponentially, and that is why the solutions are unstable. It's a common problem with multi-step explicit algorithms.
  9. Sep 29, 2009 #8
    The reason you go backward in time yet a central difference in space is precisely due to the ease involved in solving. If you went central in time as well, you would have an extra u evaluated at n-1, which would disturb the tri-diagonal structure of the RHS.

    The reason the 3 point scheme is used for space is also for the same reason that you mentioned, for ease in computation. There are problems where a 5-point difference scheme is used, but then the physics is different there.

    As a good exercise, you could try using a 3 point difference scheme for time and compare your results.

    Another reason I came up with is that in a diffusion problem, the state at any time t would only depend on time t-1. Think about it, the temperature at a point now does not care what the temperature at that same point was say ten delta time back. All in all, its just physics!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook