April 2019
Intermediate to advanced
426 pages
11h 13m
English
The Python implementation of the Crank-Nicolson method is given in the following FDCnEu class, which inherits from the FDExplicitEu class and overrides only the setup_coefficients and traverse_grid methods:
In [ ]: import numpy as np import scipy.linalg as linalg """ Crank-Nicolson method of Finite Differences """ class FDCnEu(FDExplicitEu): def setup_coefficients(self): self.alpha = 0.25*self.dt*( (self.sigma**2)*(self.i_values**2) - \ self.r*self.i_values) self.beta = -self.dt*0.5*( (self.sigma**2)*(self.i_values**2) + self.r) self.gamma = 0.25*self.dt*( (self.sigma**2)*(self.i_values**2) + self.r*self.i_values) self.M1 = -np.diag(self.alpha[2:self.M], ...
Read now
Unlock full access