Numerical solution to 2nd order ODE - where does this approximation come from?

170 Views Asked by At

I have been looking through some notes on approximating solutions to 2nd order ODEs, and came across this approximation $$\left(\frac{d^2y}{dx^2}\right)_0 \approx \frac{y_1 - 2y_0 + y_{-1}}{h^2}$$ but there is no indication about where this comes from. There are similar first order approximations given, but I understand where these come from.

I am also not very sure how to use the approximation, so if someone could give an example or link to some material, that'd be useful.

2

There are 2 best solutions below

0
On BEST ANSWER

Write down the Taylor series $$ y(\pm h)=y(0)\pm y'(0)h+\frac12y''(0)h^2+\frac16y'''(0)h^3+O(h^4) $$ and consider the sum and difference of both, \begin{align} y(h)-y(-h)&=2y'(0)h+O(h^3)\\ y(h)+y(-h)&=2y(0)+y''(0)h^2+O(h^4) \end{align} and solve for the derivatives. In the first derivative you get the central difference quotient $$y'(0)=\frac{y(h)-y(-h)}{2h}+O(h^2)$$ and the second derivative approximation is $$y''(0)=\frac{y(h)-2y(0)+y(-h)}{h^2}+O(h^2).$$

0
On

Let's start with an approximation of the derivative by finite differences.

The definition of the derivative can be written as follows:

$$y'(x)=\lim_{h \to 0} \frac{y(x+h)-y(x)}{h}$$

To get a numerical approximation we just discard the limit and consider $h$ a small, but finite quantity and consider a grid of $x_k=x_0+k h$, where $k=0,1,2,3,\dots$:

$$y'(x_k) \approx \frac{y(x_k+h)-y(x_k)}{h}=\frac{y(x_{k+1})-y(x_k)}{h} \equiv \frac{y_{k+1}-y_k}{h}$$


Now how to obtain the approximation to the second derivative? Let us go by definition as well:

$$y''(x)=\lim_{h \to 0} \frac{y'(x+h)-y'(x)}{h}$$

From the definition of the derivative:

$$y''(x)=\lim_{h_1 \to 0} \frac{1}{h_1} \lim_{h_2 \to 0} \left(\frac{y(x+h_1+h_2)-y(x+h_1)}{h_2}-\frac{y(x+h_2)-y(x)}{h_2} \right)$$

Here we introduced two variables for the limit to avoid confusion. But for the practical purposes of approximation we can set:

$$h_1=h_2=h$$

Then we obtain:

$$y''(x) \approx \frac{y(x+2h)-y(x+h)-(y(x+h)-y(x))}{h^2} =\frac{y(x+2h)-2y(x+h)+y(x)}{h^2}$$

Using the definition of the grid we had above, we can write:

$$y''(x_k) \approx \frac{y_{k+2}-2y_{k+1}+y_k}{h^2}$$

But this is a little asymmetric, and different from what the OP got. This approximation is called forward difference approximation.

It's not hard to get a central difference approximation instead, by using a different (also valid) definition of the derivative:

$$y'(x)=\lim_{h \to 0} \frac{y(x+h/2)-y(x-h/2)}{h}$$