import numpy as np
import matplotlib.pyplot as plt
def f(x):
return x**2
def d2f_dx2(f, x, h):
return (f(x+h)+f(x-h)-2*f(x))/h**2
if __name__=='__main__':
x=np.linspace(-2, 2, 1000)
_d2f_dx2=np.zeros_like(x, float)
for i in range(len(x)):
_d2f_dx2[i]=d2f_dx2(f, x[i], 1e-6)
plt.plot(x, _d2f_dx2, 'ro', ms=2)
plt.ylim([1.5, 2.5])
plt.title(r"$\frac{d^2}{dx^2} x^2$")
plt.show()