Using the finite difference method for the boundary value problem with Neumann’s boundary conditions

algorithmsnumerical methodsordinary differential equations

$$
\begin{cases}
y'' = y + 8 + 3x(1 – x) \\
y'(0) = -3 \\
y'(1) = e – \frac{1}{e} + 3
\end{cases}
$$

I'm trying to solve boundary value problem using finite difference method but first of all I need to system of equations

$$
y'(0) = \frac{-3y_{0} + 4y_{1} – y_2}{2h}
$$

$$
y'(1) = \frac{-3y_{N – 3} + 4y_{N – 2} – y_{N – 1}}{2h}
$$

$$
\begin{cases}
\frac{-3y_{0} + 4y_{1} – y_2}{2h} = -3\\
\frac{y_{i – 1} – 2y_i + y_{i + 1}}{h^2} = y_{i} + 8 + 3x_{i}(1 – x_{i}) \\
\frac{y_{N – 2} – 2y_{N – 1} + y_{N}}{2h} = e – \frac{1}{e} + 3
\end{cases}
$$

Did I get the right system? If so, how do I apply this method to the system?

Best Answer

I'm not sure what you mean by "applying this method to the system... You have written down the linear system to be solved (apart from the correction mentioned by @Ian), now you just need to solve it. Your equations are $$ -3y_0 + 4y_1-y_2 = - 6h $$ $$ y_{i-1}-(2+h^2)y_i+y_{i+1} = 8h^2+3h^2 x_i(1-x_i), \quad i = 1, \cdots, n $$ $$ y_{n-1}-4y_n+3y_{n+1} = 2h (e-e^{-1}+3) $$

so, apart from the first and last lines, you have a tridiagonal system. Below you can visualize the numerical solution with $n=10$ (dots), compared to the exact solution $y(x)=-2 + e^{-t} + e^t - 3 t + 3 t^2$ (line).

It is also very instructive to observe the behaviour of the numerical solution when you use first order approximations of the derivatives to enforce the Neumann conditions, i.e. what happens if you replace the fisrt and last equations by $y_1-y_0=-3h$ and $y_{n+1}-y_n = h(e-e^{-1}+3)$.

enter image description here