To solve ${d^2y \over dx^2} =f(x)$, $0 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})$?
Two-Point boundary value problem
3
$\begingroup$
ordinary-differential-equations
numerical-methods
1 Answers
2
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.
-
0Thanks @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})$? – 2012-05-10
-
0@Richard Yes, that's correct, except for a typo (you wrote $f_{j+1}$ where it should be $y_{j+1}$). – 2012-05-10