Finite Difference Method - clarification of a term

1. Jul 17, 2012

1. The problem statement, all variables and given/known data

I'm doing a class on Numerical Solutions of DE and I have my first assignment. The problem is stated:

Consider the following second order boundary value problem:

$\epsilon \frac{d^{2}y}{dx^{2}} + \frac{1}{2+x-x^{2}} \frac{dy}{dx}-\frac{2}{1+x}y = 4sin(3x), y(0) = 2, y(2) = 1, \epsilon = 0.01, h = 2N, x_{i} = ih$

We can approximate the derivatives at the N-1 interior points using the following finite difference approximations:

$y'(x_{i}) = \frac{-y_{i-1} + y_{i+1}}{2h} + O(h^{2})$ and $y''(x_{i}) = \frac{y_{i-1} - 2y_{i} + y_{i+1}}{h^{2}} + O(h^{2})$

2. Relevant equations

as above.

3. The attempt at a solution

I don't understand the meaning of the $O(h^{2})$ term for each of the finite difference approximations. I think it refers to the error but I don't know how to account for it in my workings.

As for solving the boundary problem, my next step is to sub in y'(x) and y''(x) to the equation and work out equations that I can use to form a tri-diagonal matrix and then compute the solution and plot it, I think I can do this part ok, we worked through a similar problem in class but it didn't contain this $O(h^{2})$ term

2. Jul 17, 2012

HallsofIvy

Staff Emeritus
It means that the error is no larger than a multiple of $h^2$. That is, the smaller you make the step the smaller the error is- on the order of $h^2$. You do NOT include that in the solution.

3. Jul 17, 2012

OK thanks HallsOfIvy, I'll get to solving it!

4. Jul 17, 2012

Muphrid

If you want a numerical estimate of the error, you should go back to the Taylor series used to derive the fininte difference approximations and compute those $h^2$ terms. This is a good thing to do if you're being extra careful and want to know these approximations are good enough.

5. Jul 19, 2012

Thanks Muphrid, I will do that. I haven't covered Taylor Series before, I think I have a bit of a gap in my knowledge. I'm doing a fairly condensed 'computational math' major for my comp sci degree and we skipped through calc I-III a bit too quickly.

I have one more question with regards to this boundary value problem. I've created my system of 3 equations but I'm not sure whether to keep the $x_{i}$ terms as they are, or put them in terms of $h$ which would allow me to simplify my equations a lot further. The $x_{i}$ is the $x$ term at each step $h$, so $x_{i} = x_{0} + h = 0 + h$

I think it's just a cosmetic operation, but it will also save me some computation when I program my solution. I'm just a bit unsure of the correct protocol to follow.

6. Jul 19, 2012

Muphrid

I think given a literal reading of the problem, $x_0 = 0$ and $x_1 = h$. In this problem, yes, you have an evenly spaced discretization and can simplify the equations accordingly, and this is a good thing to do--to take advantage of that property.

On the other hand, in general you won't be given an evenly spaced grid and it might be useful to keep the formulas general--just store the array of the actual $x_i$--so that the program could be reused if at some point you had to change the grid spacing. That might not be relevant for the assignment at hand, but on a practical level, knowing whether you will always have that uniform spacing or might want to change it, make it adaptible or what-have-you, is something I consider important.

Just a little bit about Taylor series: here's an example of calculating the error inherent to a finite-difference approximation. We can approximate, for example, $y_{i+1}$ as $y_i + h y'_i+ h^2 y''_i/2 + h^3 y'''_i/6 + O(h^4)$. Similarly, $y_{i-1} = y_i - h y'_i + h^2 y''_i/2 - h^3 y'''_i/6 + O(h^4)$. Putting these into your formula for $y'_i$ gives

$$y_i' \approx \frac{y_{i+1}- y_{i-1}}{2h} = \frac{2hy_i' + h^3 y_i'''/6}{2h} + O(h^3) = y_i' + \frac{1}{12} h^2 y_i''' + O(h^3)$$

The leading, lowest-order residual term is the $h^2 y_i'''/12$, and this is usually just considered the error itself.

7. Jul 19, 2012

Thanks again Muphrid! I did make a typo in my post, I should have written $x_{i} = x_{0} + ih$, I forgot the $i$ term, but you've clarified the point for me anyway.