Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

To solve ${d^2y \over dx^2} =f(x)$, $0<x<1$ with $y(0)=\alpha, y(1) = \beta$. We can get a finite difference approximation by taking $$\frac{y_{j+1}-2y_j+y_{j-1}}{h^2} =f_j \\\Rightarrow \frac{1}{2}y_{j+1}-y_j+\frac{1}{2}y_{j-1} =\frac{h^2}{2}f_j$$

Then we get a system of linear equations which can be written as $\left(\begin{array}{ccccc} -1 & 1/2 & 0 &0 &0 \\ 1/2 & -1 & 1/2 &0 &0\\ 0 & 1/2 & -1 &1/2&0\\ 0 & 0 & 1/2&-1 &1/2\\ 0 & 0 & 0 &1/2 &-1\end{array} \right) \cdot \left(\begin{array}{c} y_1 \\ y_2 \\ y_3 \\ y_4 \\ y_5 \end{array} \right) = \left(\begin{array}{c} \frac{h^2}{2}f_1 -\frac{\alpha}{2}\\ \frac{h^2}{2}f_2 \\ \frac{h^2}{2}f_3 \\ \frac{h^2}{2}f_4 \\ \frac{h^2}{2}f_5 -\frac{\beta}{2} \end{array} \right)$

which we can solve by gaussian elimination.

I got the idea from http://www2.imperial.ac.uk/~pavl/finite_dff.pdf


I understand the above, but how do I calculate/find/write out $f_2$, $f_3$, $f_4$ etc.? What if my DE is$$-{d^2y\over dx^2} + {dy\over dx} =x \Leftrightarrow {d^2y\over dx^2}={dy\over dx}-x $$ with $u(0)=\alpha, u(1) = \beta$?


Edit: I rearranged the equation and got

$f_{j+1}(1-\frac{h}{2})+y_{j-1}(1+\frac{h}{2})+y_j(-2)=h^2f_j$.

$j=1 \Rightarrow f_{2}(1-\frac{h}{2})+y_{0}(1+\frac{h}{2})+y_1(-2)=h^2f_1$.

So does $h^2f_1 = \frac{1}{36}\cdot(-\frac{1}{6})?$ And does $h^2f_2 = \frac{1}{36}\cdot(-\frac{2}{6})$?

share|improve this question

1 Answer 1

The answer to your first question is hidden in the PDF file you link to. The $f_j$ are defined by $f_j = f(x_j)$ with $x_j = jh = j/(N+1)$ where $N$ in the number of grid points. In your example with the 5-by-5 matrix, $h=\frac16$ so $f_j = f(j/h)$.

For your second question, you need to take care of the extra term $\frac{dy}{dx}$. One possibility (the most obvious one for me) is to use the approximation $$ \frac{dy}{dx} \approx \frac{y_{j+1} - y_{j-1}}{2h}, $$ compare with equation (2) in the PDF file. This will lead to a similar matrix equation as the one you wrote down.

share|improve this answer
    
Thanks @JitseNiesen The main part I was confused on is how to calculate the $f_j$. Could you see if what I've done is correct? I rearranged the equation and got $f_{j+1}(1-\frac{h}{2})+y_{j-1}(1+\frac{h}{2})+y_j(-2)=h^2f_j$. For example, $j=1 \Rightarrow f_{2}(1-\frac{h}{2})+y_{0}(1+\frac{h}{2})+y_1(-2)=h^2f_1$. So does $h^2f_1 = \frac{1}{36}\cdot(-\frac{1}{6})?$ And does $h^2f_2 = \frac{1}{36}\cdot(-\frac{2}{6})$? –  Richard May 10 '12 at 8:14
    
@Richard Yes, that's correct, except for a typo (you wrote $f_{j+1}$ where it should be $y_{j+1}$). –  Jitse Niesen May 10 '12 at 13:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.