HOME

TheInfoList



OR:

In
numerical analysis Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods ...
, the Crank–Nicolson method is a
finite difference method In numerical analysis, finite-difference methods (FDM) are a class of numerical techniques for solving differential equations by approximating derivatives with finite differences. Both the spatial domain and time interval (if applicable) are ...
used for numerically solving the heat equation and similar
partial differential equations In mathematics, a partial differential equation (PDE) is an equation which imposes relations between the various partial derivatives of a multivariable function. The function is often thought of as an "unknown" to be solved for, similarly to ...
. It is a second-order method in time. It is implicit in time, can be written as an implicit Runge–Kutta method, and it is
numerically stable In the mathematical subfield of numerical analysis, numerical stability is a generally desirable property of numerical algorithms. The precise definition of stability depends on the context. One is numerical linear algebra and the other is algorit ...
. The method was developed by John Crank and
Phyllis Nicolson Phyllis Nicolson (21 September 1917 – 6 October 1968) was a British mathematician and physicist best known for her work on the Crank–Nicolson method together with John Crank. Early life and education Nicolson was born Phyllis Lockett i ...
in the mid 20th century. For diffusion equations (and many other equations), it can be shown the Crank–Nicolson method is unconditionally stable. However, the approximate solutions can still contain (decaying) spurious oscillations if the ratio of time step \Delta t times the
thermal diffusivity In heat transfer analysis, thermal diffusivity is the thermal conductivity divided by density and specific heat capacity at constant pressure. It measures the rate of transfer of heat of a material from the hot end to the cold end. It has the SI ...
to the square of space step, \Delta x^2, is large (typically, larger than 1/2 per
Von Neumann stability analysis The term ''von'' () is used in German language surnames either as a nobiliary particle indicating a noble patrilineality, or as a simple preposition used by commoners that means ''of'' or ''from''. Nobility directories like the ''Almanach de Go ...
). For this reason, whenever large time steps or high spatial resolution is necessary, the less accurate
backward Euler method In numerical analysis and scientific computing, the backward Euler method (or implicit Euler method) is one of the most basic numerical methods for the solution of ordinary differential equations. It is similar to the (standard) Euler method, but d ...
is often used, which is both stable and immune to oscillations.


The method

The Crank–Nicolson method is based on the
trapezoidal rule In calculus, the trapezoidal rule (also known as the trapezoid rule or trapezium rule; see Trapezoid for more information on terminology) is a technique for approximating the definite integral. \int_a^b f(x) \, dx. The trapezoidal rule works by ...
, giving second-order convergence in time. For linear equations, the trapezoidal rule is equivalent to the implicit midpoint method the simplest example of a Gauss–Legendre implicit Runge–Kutta method which also has the property of being a geometric integrator. For example, in one dimension, suppose the partial differential equation is : \frac = F\left(u, x, t, \frac, \frac\right). Letting u(i \Delta x, n \Delta t) = u_i^n and F_i^n = F evaluated for i, n and u_i^n, the equation for Crank–Nicolson method is a combination of the forward Euler method at n and the
backward Euler method In numerical analysis and scientific computing, the backward Euler method (or implicit Euler method) is one of the most basic numerical methods for the solution of ordinary differential equations. It is similar to the (standard) Euler method, but d ...
at ''n'' + 1 (note, however, that the method itself is ''not'' simply the average of those two methods, as the backward Euler equation has an implicit dependence on the solution): : \frac = F_i^n\left(u, x, t, \frac, \frac\right) \qquad \text, : \frac = F_i^\left(u, x, t, \frac, \frac\right) \qquad \text, : \frac = \frac \left F_i^\left(u, x, t, \frac, \frac\right) + F_i^n\left(u, x, t, \frac, \frac\right) \right\qquad \text. Note that this is an ''implicit method'': to get the "next" value of ''u'' in time, a system of algebraic equations must be solved. If the partial differential equation is nonlinear, the discretization will also be nonlinear, so that advancing in time will involve the solution of a system of nonlinear algebraic equations, though linearizations are possible. In many problems, especially linear diffusion, the algebraic problem is tridiagonal and may be efficiently solved with the
tridiagonal matrix algorithm In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), is a simplified form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A tridiagon ...
, which gives a fast \mathcal(N) direct solution, as opposed to the usual \mathcal(N^3) for a full matrix, in which N indicates the matrix size.


Example: 1D diffusion

The Crank–Nicolson method is often applied to diffusion problems. As an example, for linear diffusion, : \frac = a \frac, applying a
finite difference A finite difference is a mathematical expression of the form . If a finite difference is divided by , one gets a difference quotient. The approximation of derivatives by finite differences plays a central role in finite difference methods for t ...
spatial discretization for the right-hand side, the Crank–Nicolson discretization is then : \frac = \frac\left( (u_^ - 2 u_i^ + u_^) + (u_^n - 2 u_i^n + u_^n) \right) or, letting r = \frac, : -r u_^ + (1 + 2r) u_i^ - r u_^ = r u_^n + (1 - 2r) u_i^n + r u_^n. Given that the terms on the right-hand side of the equation are known, this is a tridiagonal problem, so that u_i^ may be efficiently solved by using the
tridiagonal matrix algorithm In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), is a simplified form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A tridiagon ...
in favor over the much more costly
matrix inversion In linear algebra, an -by- square matrix is called invertible (also nonsingular or nondegenerate), if there exists an -by- square matrix such that :\mathbf = \mathbf = \mathbf_n \ where denotes the -by- identity matrix and the multiplicati ...
. A quasilinear equation, such as (this is a minimalistic example and not general) : \frac = a(u) \frac, would lead to a nonlinear system of algebraic equations, which could not be easily solved as above; however, it is possible in some cases to linearize the problem by using the old value for a, that is, a_i^n(u) instead of a_i^(u). Other times, it may be possible to estimate a_i^(u) using an explicit method and maintain stability.


Example: 1D diffusion with advection for steady flow, with multiple channel connections

This is a solution usually employed for many purposes when there is a contamination problem in streams or rivers under steady flow conditions, but information is given in one dimension only. Often the problem can be simplified into a 1-dimensional problem and still yield useful information. Here we model the concentration of a solute contaminant in water. This problem is composed of three parts: the known diffusion equation (D_x chosen as constant), an advective component (which means that the system is evolving in space due to a velocity field), which we choose to be a constant ''Ux'', and a lateral interaction between longitudinal channels (''k''): where ''C'' is the concentration of the contaminant, and subscripts ''N'' and ''M'' correspond to ''previous'' and ''next'' channel. The Crank–Nicolson method (where ''i'' represents position, and ''j'' time) transforms each component of the PDE into the following: Now we create the following constants to simplify the algebra: : \lambda = \frac, : \alpha = \frac, : \beta = \frac, and substitute (), (), (), (), (), (), ''α'', ''β'' and ''λ'' into (). We then put the ''new time'' terms on the left (''j'' + 1) and the ''present time'' terms on the right (''j'') to get : -\beta C_^ - (\lambda + \alpha)C_^ + (1 + 2\lambda + 2\beta)C_i^ - (\lambda - \alpha)C_^ - \beta C_^ = : \qquad \beta C_^j + (\lambda + \alpha)C_^j + (1 - 2\lambda - 2\beta)C_i^j + (\lambda - \alpha)C_^j + \beta C_^j. To model the ''first'' channel, we realize that it can only be in contact with the following channel (''M''), so the expression is simplified to : -(\lambda + \alpha)C_^ + (1 + 2\lambda + \beta)C_i^ - (\lambda - \alpha)C_^ - \beta C_^ = : \qquad +(\lambda + \alpha)C_^j + (1 - 2\lambda - \beta)C_i^j + (\lambda - \alpha)C_^j + \beta C_^j. In the same way, to model the ''last'' channel, we realize that it can only be in contact with the previous channel (''N''), so the expression is simplified to : -\beta C_^ - (\lambda + \alpha)C_^ + (1 + 2\lambda + \beta)C_i^ - (\lambda - \alpha)C_^ = : \qquad \beta C_^j + (\lambda + \alpha)C_^j + (1 - 2\lambda - \beta)C_i^j + (\lambda - \alpha)C_^j. To solve this linear system of equations, we must now see that boundary conditions must be given first to the beginning of the channels: : C_0^j: initial condition for the channel at present time step, : C_^: initial condition for the channel at next time step, : C_^j: initial condition for the previous channel to the one analyzed at present time step, : C_^j: initial condition for the next channel to the one analyzed at present time step. For the last cell of the channels (''z''), the most convenient condition becomes an adiabatic one, so : \frac_ = \frac = 0. This condition is satisfied if and only if (regardless of a null value) : C_^ = C_^. Let us solve this problem (in a matrix form) for the case of 3 channels and 5 nodes (including the initial boundary condition). We express this as a linear system problem: : \mathbf\,\mathbf = \mathbf\,\mathbf + \mathbf, where : \mathbf = \begin C_^\\ C_^ \\ C_^ \\ C_^ \\ C_^\\ C_^ \\ C_^ \\ C_^ \\ C_^\\ C_^ \\ C_^ \\ C_^ \end, \quad \mathbf = \begin C_^j\\ C_^j \\ C_^j \\ C_^j \\ C_^j\\ C_^j \\ C_^j \\ C_^j \\ C_^j\\ C_^j \\ C_^j \\ C_^j \end. Now we must realize that AA and BB should be arrays made of four different subarrays (remember that only three channels are considered for this example, but it covers the main part discussed above): : \mathbf = \begin AA1 & AA3 & 0 \\ AA3 & AA2 & AA3 \\ 0 & AA3 & AA1 \end, \quad \mathbf = \begin BB1 & -AA3 & 0 \\ -AA3 & BB2 & -AA3 \\ 0 & -AA3 & BB1 \end, where the elements mentioned above correspond to the next arrays, and an additional 4×4 full of zeros. Please note that the sizes of AA and BB are 12×12: : \mathbf = \begin (1 + 2\lambda + \beta) & -(\lambda - \alpha) & 0 & 0 \\ -(\lambda + \alpha) & (1 + 2\lambda + \beta) & -(\lambda - \alpha) & 0 \\ 0 & -(\lambda + \alpha) & (1 + 2\lambda + \beta) & -(\lambda - \alpha) \\ 0 & 0 & -2\lambda & (1 + 2\lambda + \beta) \end, : \mathbf = \begin (1 + 2\lambda + 2\beta) & -(\lambda - \alpha) & 0 & 0 \\ -(\lambda + \alpha) & (1 + 2\lambda + 2\beta) & -(\lambda - \alpha) & 0 \\ 0 & -(\lambda + \alpha) & (1 + 2\lambda + 2\beta) & -(\lambda - \alpha) \\ 0 & 0 & -2\lambda & (1 + 2\lambda + 2\beta) \end, : \mathbf = \begin -\beta & 0 & 0 & 0 \\ 0 & -\beta & 0 & 0 \\ 0 & 0 & -\beta & 0 \\ 0 & 0 & 0 & -\beta \end, : \mathbf = \begin (1 - 2\lambda - \beta) & (\lambda - \alpha) & 0 & 0 \\ (\lambda + \alpha) & (1 - 2\lambda - \beta) & (\lambda - \alpha) & 0 \\ 0 & (\lambda + \alpha) & (1 - 2\lambda - \beta) & (\lambda - \alpha) \\ 0 & 0 & 2\lambda & (1 - 2\lambda - \beta) \end, : \mathbf = \begin (1 - 2\lambda - 2\beta) & (\lambda - \alpha) & 0 & 0 \\ (\lambda + \alpha) & (1 - 2\lambda - 2\beta) & (\lambda - \alpha) & 0 \\ 0 & (\lambda + \alpha) & (1 - 2\lambda - 2\beta) & (\lambda - \alpha) \\ 0 & 0 & 2\lambda & (1 - 2\lambda - 2\beta) \end. The d vector here is used to hold the boundary conditions. In this example it is a 12×1 vector: : \mathbf = \begin (\lambda + \alpha)(C_^ + C_^j) \\ 0 \\ 0 \\ 0 \\ (\lambda + \alpha)(C_^ + C_^j) \\ 0 \\ 0 \\ 0 \\ (\lambda + \alpha)(C_^ + C_^j) \\ 0 \\ 0 \\ 0 \end. To find the concentration at any time, one must iterate the following equation: : \mathbf = \mathbf^ (\mathbf\,\mathbf + \mathbf).


Example: 2D diffusion

When extending into two dimensions on a uniform Cartesian grid, the derivation is similar and the results may lead to a system of band-diagonal equations rather than tridiagonal ones. The two-dimensional heat equation : \frac = a \nabla^2 u, : \frac = a \left(\frac + \frac\right) can be solved with the Crank–Nicolson discretization of : \begin u_^ &= u_^n + \frac \frac \big u_^ + u_^ + u_^ + u_^ - 4u_^) \\ &+ (u_^n + u_^n + u_^n + u_^n - 4u_^n)\big \end assuming that a square grid is used, so that \Delta x = \Delta y. This equation can be simplified somewhat by rearranging terms and using the CFL number : \mu = \frac. For the Crank–Nicolson numerical scheme, a low CFL number is not required for stability, however, it is required for numerical accuracy. We can now write the scheme as : (1 + 2\mu)u_^ - \frac\left(u_^ + u_^ + u_^ + u_^\right) = : \qquad (1 - 2\mu)u_^ + \frac\left(u_^ + u_^ + u_^ + u_^\right). Solving such a linear system is not practical due to extremely high time complexity of solving a linear system by the means of Gaussian elimination or even Strassen algorithm. Hence an
alternating-direction implicit method In numerical linear algebra, the alternating-direction implicit (ADI) method is an iterative method used to solve Sylvester matrix equations. It is a popular method for solving the large matrix equations that arise in systems theory and control, an ...
can be implemented to solve the numerical PDE, whereby one dimension is treated implicitly, and other dimension explicitly for half of the assigned time step and conversely for the remainder half of the time step. The benefit of this strategy is that the implicit solver only requires a
tridiagonal matrix algorithm In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), is a simplified form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A tridiagon ...
to be solved. The difference between the true Crank–Nicolson solution and ADI approximated solution has an order of accuracy of O(\Delta t^4) and hence can be ignored with a sufficiently small time step.


Crank-Nicolson for nonlinear problems

Because the Crank-Nicolson method is implicit, it is generally impossible to solve exactly. Instead, an iterative technique should be used to converge to the . One option is to use Newton's method to converge on the prediction, but this requires the computation of the Jacobian. For a high-dimensional system like those in
computational fluid dynamics Computational fluid dynamics (CFD) is a branch of fluid mechanics that uses numerical analysis and data structures to analyze and solve problems that involve fluid flows. Computers are used to perform the calculations required to simulate ...
or
numerical relativity Numerical relativity is one of the branches of general relativity that uses numerical methods and algorithms to solve and analyze problems. To this end, supercomputers are often employed to study black holes, gravitational waves, neutron stars a ...
, it may be infeasible to compute this Jacobian. A Jacobian-free alternative is
fixed-point iteration In numerical analysis, fixed-point iteration is a method of computing fixed points of a function. More specifically, given a function f defined on the real numbers with real values and given a point x_0 in the domain of f, the fixed-point itera ...
. If f is the velocity of the system, then the Crank-Nicolson prediction will be a fixed point of the map \Phi(x) = x_0 + \frac\left f(x_0) + f(x) \right. If the map iteration x^ = \Phi(x^) does not converge, the parameterized map \Theta(x,\alpha) = \alpha x + (1-\alpha)\Phi(x), with \alpha \in(0,1) , may be better behaved. In expanded form, the update formula is x^ = \alpha x^i + (1-\alpha)\left x_0 + \frac \left( f(x_0) + f(x^i) \right) \right, where x^i is the current guess and x_0 is the previous time-step. Even for high dimensional systems, iteration of this map can converge surprisingly quickly.


Application in financial mathematics

Because a number of other phenomena can be modeled with the heat equation (often called the diffusion equation in
financial mathematics Mathematical finance, also known as quantitative finance and financial mathematics, is a field of applied mathematics, concerned with mathematical modeling of financial markets. In general, there exist two separate branches of finance that require ...
), the Crank–Nicolson method has been applied to those areas as well. Particularly, the Black–Scholes option pricing model's
differential equation In mathematics, a differential equation is an equation that relates one or more unknown functions and their derivatives. In applications, the functions generally represent physical quantities, the derivatives represent their rates of change, an ...
can be transformed into the heat equation, and thus numerical solutions for
option pricing In finance, a price (premium) is paid or received for purchasing or selling options. This article discusses the calculation of this premium in general. For further detail, see: for discussion of the mathematics; Financial engineering for the imple ...
can be obtained with the Crank–Nicolson method. The importance of this for finance is that option pricing problems, when extended beyond the standard assumptions (e.g. incorporating changing dividends), cannot be solved in closed form, but can be solved using this method. Note however, that for non-smooth final conditions (which happen for most financial instruments), the Crank–Nicolson method is not satisfactory as numerical oscillations are not damped. For
vanilla option In finance, an option is a contract which conveys to its owner, the ''holder'', the right, but not the obligation, to buy or sell a specific quantity of an underlying asset or instrument at a specified strike price on or before a specified dat ...
s, this results in oscillation in the gamma value around the
strike price In finance, the strike price (or exercise price) of an option is a fixed price at which the owner of the option can buy (in the case of a call), or sell (in the case of a put), the underlying security or commodity. The strike price may be set ...
. Therefore, special damping initialization steps are necessary (e.g., fully implicit finite difference method).


See also

*
Financial mathematics Mathematical finance, also known as quantitative finance and financial mathematics, is a field of applied mathematics, concerned with mathematical modeling of financial markets. In general, there exist two separate branches of finance that require ...
*
Trapezoidal rule In calculus, the trapezoidal rule (also known as the trapezoid rule or trapezium rule; see Trapezoid for more information on terminology) is a technique for approximating the definite integral. \int_a^b f(x) \, dx. The trapezoidal rule works by ...


References


External links


Numerical PDE Techniques for Scientists and Engineers
open access Lectures and Codes for Numerical PDEs
An example of how to apply and implement the Crank-Nicolson method for the Advection equation
{{DEFAULTSORT:Crank-Nicolson Method Mathematical finance Numerical differential equations Finite differences