# Having trouble with discretization and boundry value problems

I have the following homework question:

Consider the boundary value problem $y''(x) + 5y'(x) − (2 + x)y(x) = e^x$ on $x ∈ (0, 2)$ with boundary conditions $3y(0) + y'(0) = 5$ and $y'(2) = 7$.

(a) Discretize the differential equation at a generic interior point $x_i$ using a standard grid.

(b) Discretize the left boundary condition$3y(0)+y'(0) = 5$ using FD2 on the standard grid.

(c) Discretize the right boundary condition $y'(2) = 7$ using BD2 on the standard grid.

I'm having some trouble figuring this out. My first instinct is to draw a 2x2 grid I should use a 1 dimensional line that looks something like this:

My best guess is that the middle point would be the interior point $x_i$ mentioned in (a). But I'm not really sure what to do from here.

I'm guessing that after I discretize the differential equation (not sure how to do that), I need to simply apply the second order forward and backward difference equations using the given boundry values in order to estimate xi? From my notes it looks like the FD2 and BD2 formulas are

$$FD2 = \frac{-3f(x) + 4f(x+h) - f(x+(2h))}{2h}$$

and

$$BD2 = \frac{3f(x) - 4f(x-h) + f(x-2h)}{2h}$$

but I'm not really too sure about BD2, something seems wrong with it. I may have copied the notes incorrectly.

Can I get some help with this problem?

• Backward difference formula should be $\frac{3f(x_{i})-4f(x_{i-1})+f(x_{i-2})}{2h}$. Also this is a 1D problem, it shouldn't be discretized into 2d grid. You should just divide the interval $[0,2]$ into $n$ subintervals. Apr 18 '15 at 17:53
• @KittyL Well now I'm not sure about any of my difference formulas D: Apr 18 '15 at 17:55
• The forward difference formula is correct. I am guessing that you should use central formula for the interior points. Apr 18 '15 at 17:59

The central difference formula for second derivative is

$$f''(x_i)=\frac{f(x_{i+1})-2f(x_i)+f(x_{i-1})}{h^2}+O(h^2)$$

The central difference formula for first derivative is

$$f'(x_i)=\frac{f(x_{i+1})-f(x_{i-1})}{2h}+O(h^2)$$

Both of these formulas are second order. Since the error terms are $O(h^2)$.

So for an interior point $x_i$, plugging these into your equation:

$$\frac{f(x_{i+1})-2f(x_i)+f(x_{i-1})}{h^2}+5 \frac{f(x_{i+1})-f(x_{i-1})}{2h} -(2+x_i)f(x_i) = e^{x_i}$$

You can simplify this by $x_i=\frac{2i}{n}$ and $h=\frac{i}{n}$ since the length of the interval is $2$.

The boundary conditions can be done similarly. Notice that you'll have to use also second order formulas for the boundary conditions since you want to maintain the second order error for the whole system.

Your formula for 2nd order forward difference is correct. For backward difference, see my comments.

For an example of first order formula, the following is the forward difference formula for first derivative(notice this is just to give you an example of first order formula. You shouldn't use this in your problem):

$$f'(x_i)=\frac{f(x_{i+1})-f(x_i)}{h}+O(h)$$

• So basically I just need the first and second derivatives of the forward, central, and backward difference formulas, and then I plug the appropriate derivative into the differential equation, simplify it, and I'm done? So for example for the left boundry I would take the forward difference first derivative and second derivative and plug them into 3y(0)+y'(0) = 5, simplify it, and I'm done? Apr 18 '15 at 19:01
• Yes, that's the idea. But you don't need second derivative formula for the left boundary. It only has $y$ and $y'$. You will use second ORDER formula for first derivative because that wouldn't hurt the order of the whole system. Apr 18 '15 at 19:03
• So I could use either the first order or the second order formulas for first derivatives because second order is higher than first order, meaning we won't lose accuracy? Apr 18 '15 at 19:10
• You should use consistently either first order or second order for the whole system. This problem is asking you to use second order. If you use second order for the interior points and first order for the boundary, you would lose accuracy. Your second order for the interior would be wasted. Apr 18 '15 at 19:14
• Okay I'm confused. So shouldn't you use the second order formula for y' and y'' in your answer? I feel like I'm misunderstanding you. Apr 18 '15 at 20:39