Skip to content

Commit 70fe0f9

Browse files
committed
tried a spaced-out stencil, and although it does better than plain forward and backward difference, it doesn't do as well as just plain first order at the edges
1 parent fa9d46c commit 70fe0f9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

pynumdiff/finite_difference/_finite_difference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def finite_difference(x, dt, num_iterations, order):
2727
dxdt_hat[-1] = dxdt_hat[-2] # using stencil -1,0 vs stencil 0,1 you get an expression for the same value
2828
elif order == 2:
2929
dxdt_hat[1:-1] = (x_hat[2:] - x_hat[:-2])/2 # second-order center-difference formula
30-
dxdt_hat[0] = (-3 * x_hat[0] + 4 * x_hat[2] - x_hat[4])/4 # use spaced out stencil to get endpoint formulas
31-
dxdt_hat[-1] = (3 * x_hat[-1] - 4 * x_hat[-3] + x_hat[-5])/4 # that do not amplify noise. See #104
30+
dxdt_hat[0] = x_hat[1] - x_hat[0]
31+
dxdt_hat[-1] = x_hat[-1] - x_hat[-2] # use first-order endpoint formulas so as not to amplify noise. See #104
3232
elif order == 4:
3333
dxdt_hat[2:-2] = (8*(x_hat[3:-1] - x_hat[1:-3]) - x_hat[4:] + x_hat[:-4])/12 # fourth-order center-difference
3434
dxdt_hat[1] = (x_hat[2] - x_hat[0])/2

0 commit comments

Comments
 (0)