Test: second-order finite differences¶

Compute the first and second derivatives of a polynomial using (forward/central/backward) finite difference formulas and compare with the exact values.

Read data¶

In [1]:
import pandas as pd
from matplotlib import pyplot as plt
from matplotlib import rcParams 
rcParams["figure.dpi"] = 200
dframe = pd.read_csv("build/poly-data.csv",header=0,comment="#")

First derivative¶

In [2]:
plt.plot(dframe["X"],dframe["DFDX"], 'x', label="f'(x)")
plt.plot(dframe["X"],dframe["DFDX_CDS"], '.',  label="f'(x) CDS")
plt.legend()
Out[2]:
<matplotlib.legend.Legend at 0x7f3a296b6c80>

Second derivative¶

In [3]:
plt.plot(dframe["X"],dframe["D2FDX2"], 'x', label="f''(x)")
plt.plot(dframe["X"],dframe["D2FDX2_CDS"], '.',  label="f''(x) CDS")
plt.legend()
Out[3]:
<matplotlib.legend.Legend at 0x7f3a295dd8d0>
In [ ]: