For the fourth derivative, this is my code:
import numpy as np
import matplotlib.pyplot as plt
pi=np.pi
x=np.arange(0,5*pi,0.03*pi)
y=np.cos(x)
h=x[4]-x[3]
"fourth derivative"
#first formula
der41=[]
x41=[]
for i in range(2,len(y)-2,1):
der41.append((y[i+2]-4*y[i+1]+6*y[i]-4*y[i-1]+y[i-2])/(h**4))
x41.append(x[i])
der41=np.array(der41)
x41=np.array(x41)
#Second formula
der42=[]
x42=[]
for i in range(3,len(y)-3,1):
der42.append((-y[i+3]+12*y[i+2]+39*y[i+1]+56*y[i]-39*y[i-1]+12*y[i-2]+y[i-3])/(6*h**4))
x42.append(x[i])
der42=np.array(der42)
x42=np.array(x42)
plt.plot(x,y,'g',x41,der41,'r',x42,der42,'b')
plt.title("Cuarta derivada")
plt.xlabel("Eje X")
plt.ylabel("Eje Y")
plt.grid()
plt.show()
This is the graph:
This code is based on the following formulas:
All three graphs should be the same "shape".
PD: Sorry if i have mistaken a word, please let me know. Thank you.


