Class CrankNicolsonHeatEquation1D
- java.lang.Object
-
- dev.nm.analysis.differentialequation.pde.finitedifference.parabolic.dim1.heatequation.CrankNicolsonHeatEquation1D
-
- All Implemented Interfaces:
PDESolver
public class CrankNicolsonHeatEquation1D extends Object implements PDESolver
The Crank-Nicolson method is an algorithm for obtaining a numerical solution to parabolic PDE problems. It is based on central difference in space, and the trapezoidal rule in time, giving second-order convergence in time. That is, the solution is computed using this implicit equation: \[ \frac{u_{j}^{k + 1} - u_{j}^{k}}{\Delta t} = \frac{\beta}{2}\left( \frac{u_{j+1}^{k+1} - 2u_{j}^{k+1} + u_{j-1}^{k+1}}{\Delta x^2} + \frac{u_{j+1}^{k} - 2u_{j}^{k} + u_{j-1}^{k}}{\Delta x^2} \right) \] where \(u^k_j = u(t_k,x_j)\) is the estimate at \((k, j)\) in the grid. This is a second-order method with a truncation error of order \(O(\Delta t^2 + \Delta x^2)\). The solution is computed along a two-dimensional grid (e.g. time and space). Note that due to the way that the boundary values are given, the resulting grid will NOT contain the values at the boundaries and attempting to access \(u^k_0\) or \(u^k_{n+1}\) will result in anUnsupportedOperationException
being thrown.- See Also:
- Wikipedia: Crank-Nicolson method
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CrankNicolsonHeatEquation1D.Coefficients
Gets the coefficients of a discretized 1D heat equation for each time step.
-
Constructor Summary
Constructors Constructor Description CrankNicolsonHeatEquation1D()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PDESolutionTimeSpaceGrid1D
solve(HeatEquation1D pde, int M, int N)
Solves the given one-dimensional heat equation.
-
-
-
Method Detail
-
solve
public PDESolutionTimeSpaceGrid1D solve(HeatEquation1D pde, int M, int N)
Solves the given one-dimensional heat equation.- Parameters:
pde
- the PDE problemM
- the number of grid points along the time-axis (excluding the initial condition)N
- the number of grid points along the space-axis (excluding the two boundaries)- Returns:
- the solution \(u(t,x)\) at the grid points
-
-