def build_gradient_matrix(self, x):
"""
:param x: grid index
:return:
"""
if x == 0 or x == self.d - 1:
raise ValueError("Boundary Conditions not treated here")
nabla_matrix = np.zeros((2, 2))
nabla_minus = self.grid[x - 1] - self.grid[x]
nabla_plus = self.grid[x + 1] - self.grid[x]
nabla_matrix[0, 0] = nabla_minus
nabla_matrix[0, 1] = nabla_plus
nabla_matrix[1, 0] = nabla_minus * nabla_minus
nabla_matrix[1, 1] = nabla_plus * nabla_plus
if linalg.det(nabla_matrix) == 0:
raise ValueError("Nabla is not invertible")
return nabla_matrix
评论列表
文章目录