# Numerical solution of 2nd order ODE

1. Nov 7, 2005

### Zurtex

Got this problem and we've been given a program which can solve for x, for the equation:
Ax = b
Where
$$A = \left( \begin{array}{rrrrrr} b & c & 0 & 0 & \cdots & 0 \\ a & b & c & 0 & \cdots & 0\\ 0 & \ddots & \ddots & \ddots & & \vdots \\ \vdots & & \ddots & \ddots & \ddots & 0 \\ \vdots & & & \ddots & \ddots & c\\ 0 & \cdots & \cdots & 0 & a & b \\ \end{array} \right)$$

If I left a = - 1, c = -1 and b = 2 + (1/n^2) (for my number of intervals n) and b = [1/n^2, 1/n^2, ..., 1/n^2]

Then I am approximation solutions to:

$$-\frac{d^2y}{dx^2} + y = 1 \quad \text{and} \quad y(0)=0 \quad y(1)=0$$

I kind of understand that (or at least I have notes in front of me which seem to conclude that fairly logically). However I am now asked to set up a similar system for:

$$-\frac{d^2y}{dx^2} + 20 \frac{dy}{dx} = 1 \quad \text{and} \quad y(0)=0 \quad y(1)=0$$

And I have no idea where to start, any help please.

Last edited: Nov 7, 2005
2. Nov 7, 2005

### saltydog

Hello Zurtex.

You start by representing the differential equation in the form of a difference equation right? I assume you're using a central difference:

$$\frac{d^2y}{dx^2}=\frac{x_{i+1}-2x_i+x_{i-1}}{h^2}$$

$$\frac{dy}{dx}=\frac{x_{i+1}-x_{i-1}}{2h}$$

Now substitute these difference equations into the DE and then arrange these m equations in m unknowns into a tri-diagonal matrix. First try and obtain the matrix you already posted using the definitions of the central differences for the derivatives.

I notice you're using n, the total number of points rather than the constant difference in x-values which is h above. 1/n and 1/n^2 is the same thing.

Remember, the equations start from x_2 and go to x_(n-1) since you already know the boundary points.

3. Nov 8, 2005

### saltydog

Hey Zurtex, I made a typo above. Should have been all y's. Sorry:

$$\frac{d^2y}{dx^2}=\frac{y_{i+1}-2y_i+y_{i-1}}{h^2}$$
$$\frac{dy}{dx}=\frac{y_{i+1}-y_{i-1}}{2h}$$

So substitute these difference quotients into the second equation:

$$-\left(\frac{y_{i+1}-2y_i+y_{i-1}}{h^2}\right)+20\left(\frac{y_{i+1}-y_{i-1}}{2h}\right)=1$$

Simplify, end up with some difference relation:

$$ay_{n-1}+by_n+cy_{n+1}=d$$

Ok, so for example, split up the interval (0,1) into 10 parts. You already know what y1 and y10 are right? That's the boundary conditions. So you have 8 unknowns left: y2, y3 . . . y8. Now set up that matrix equation which expresses these 8 unknowns in terms of 8 equations. The coefficient matrix is then the tridiagonal matrix.

Last edited: Nov 8, 2005
4. Nov 8, 2005

### Zurtex

*hugs saltydog* this seems so much easier now then when my lecturer explained it.