Derivatives

This simulation calculates a base function

y = f(x)

for 1000 x- values in a given interval.

With h the difference between consecutive x values sufficiently small, the first derivative (differential quotient) is approximated by the difference quotient

y(1)(x) = (1/2h) [y(x+h) - y(x-h)]

The second derivative is approximated as the difference quotient of the first difference quotient

y(2)(x)= (1/2h) [y(1)(x+h) - y(1)(x-h)] = (1/2h)2 [y(x+2h) - 2y(x) + y(x-1h)]

This algorithm can be continued, leading to the code lines for the base function a[0] and the derivatives up to the 9th order a[9].

For the predefined functions and intervals most approximations do not visually differ from the analytical derivatives. This can be best controlled with the sine function, where the derivatives look the same at every 4th order.

For still higher derivatives, the limits of the accuracy of the approximation and also the computing accuracy are stressed, and noisy artifacts appear.

Code: With s = 1/(2h)

a0[j]=Math.pow(s,0)*y[0][j];

a1[j]=Math.pow(s,1)*(y2[1][j]-y1[1][j]);

a2[j]=Math.pow(s,2)*(y2[2][j]-2*y2[0][j]+y1[2][j]);

a3[j]=Math.pow(s,3)*(y2[3][j]-3*y2[1][j]+3*y1[1][j]-y1[3][j]);

a4[j]=Math.pow(s,4)*(y2[4][j]-4*y2[2][j]+6*y2[0][j]-4*y1[2][j]+y1[4][j]);

a5[j]=Math.pow(s,5)*(y2[5][j]-5*y2[3][j]+10*y2[1][j]-10*y1[1][j]+5*y1[3][j]-y1[5][j]);

a6[j]=Math.pow(s,6)*(y2[6][j]-6*y2[4][j]+15*y2[2][j]-20*y2[0][j]+15*y1[2][j]-6*y1[4][j]+y1[6][j]);

a7[j]=Math.pow(s,7)*(y2[7][j]-7*y2[5][j]+21*y2[3][j]-35*y2[1][j]+35*y1[1][j]-21*y1[3][j]+7*y1[5][j]-y1[7][j]);

a8[j]=Math.pow(s,8)*(y2[8][j]-8*y2[6][j]+28*y2[4][j]-56*y2[2][j]+70*y2[0][j]-56*y1[2][j]+28*y1[4][j]-8*y1[6][j]+y1[8][j]);

a9[j]=Math.pow(s,9)*(y2[9][j]-9*y2[7][j]+36*y2[5][j]-84*y2[3][j]+126*y2[1][j]-126*y1[1][j]+84*y1[3][j]-36*y1[5][j]+9*y1[7][j]-y1[9][j]);

The integers in the formulas follow simple generation rules, so that the series can be easily generated or continued.