How to find the second derivative?

1.2k Views Asked by At

I use this article from Wikipedia to build it in my program. How to find the second derivative in $(x_i, y_i)$ point of this cubic interpolation, if I know other $(x_j, y_j)$ points?

2

There are 2 best solutions below

2
On BEST ANSWER

A cubic Hermite spline guarantees continuity of the function and it's first derivative in the dataset points, not of the second derivative. Hence, $f''(x_i)$ will not be well defined (more precisely, it will not have a limit, it will have one value at the left and other at the right).

A standard simple estimate of the second derivative for discrete points, at point $(x_i,y_i)$ would be:

$$ \left(\frac{\Delta y_{+}}{\Delta x_{+}}-\frac{\Delta y_{-}}{\Delta x_{-}}\right)\frac{2}{\Delta x_{+-}}$$ where $\Delta y_{+}=y_{i+1}-y_{i}$, $\Delta y_{-}=y_{i}-y_{i-1}$ $\Delta x_{+}=x_{i+1}-x_{i}$, $\Delta x_{-}=x_{i}-x_{i-1}$, $\Delta x_{+-}=x_{i+1}-x_{i-1}$

0
On

To calulated them by hand, use first principles twice, i.e.:

$f'(x)\approx\frac{f(x+h)-f(x)}{h}$, and similarly $f''(x)\approx \frac{f(x+2h)-2f(x+h)+f(x)}{h^2}$, so if you want to compute the second derivative at a point, you will need atleast two points "$h$" close to it, where $h$ is some mesh size.

Let me make this more explicit to your situation, if you have $(x_1,y_1),(x_2,y_2),(x_3,y_3)$ where $x_3\gt x_2\gt x_1$ and the distance between the $x$ coordinates is the same. Let this size be $h$.

Then $f''(x_1)\approx\frac{y_3-2y_2+y_1}{h^2}$

Or if you have a non uniform mesh, i.e. $x_3-x_2=k,x_2-x_1=h,h\ne k$, then:

$f''(x_1)\approx\frac{y_3-2y_2+y_1}{hk}$