Deriving the linear system for a fnite difference approximation of a boundary value problem

38 Views Asked by At

Consider the boundary value problem $$u^{''} (x) + u'(x) =f(x), \quad 0 \le x \le 1$$ with $u(0) = u_\alpha$ and $u(1) = u_\beta.$

The goal is to derive the linear system for a finite difference approximation of $u(x)$ at points $x_0 = 0, \ldots, x_{n+1} = 1.$

After reading a similar post from here How to put the finite difference in a a matrix to solve the linear system, I manage to write out the linear system for the above problem and I am seeking proofreading, addition and subtraction of the following:

The three mesh are: \begin{align*} x_0 & = u_\alpha, \\ x_1 & = \frac{u_\alpha + u_\beta}{n} \\ x_2 & = u_\beta \end{align*} From boundary conditions, we get

$y_0 = u(x_0 = 0) = u_\alpha$ and

$y_{n+1} = u(x_{n+1 } = 1) = u_\beta.$

We then seek to approximate $y_1 \approx u(x_1), \ldots, y_n \approx u(x_n)$

\begin{align} u''(x_i) + u'(x_i) & \approx \frac{y_{i+1} - 2y_i + y_{i-1}}{h^2} + \frac{y_{i+1} - y_i }{2h} = f(x_i)\\ \\ u''(x_1) + u'(x_1) & \approx \frac{y_{2} - 2y_1 + y_{0}}{h^2} + \frac{y_{2} - y_1 }{2h} = \frac{(2+h)y_2 - 4y_1 + (2-h)y_0}{2h^2} = f(x_1)\\\\ u''(x_2) + u'(x_2) & \approx \frac{y_{3} - 2y_2 + y_{1}}{h^2} + \frac{y_{3} - y_2 }{2h} = \frac{(2+h)y_3 - 4y_2 + (2-h)y_1}{2h^2} = f(x_2)\\\\ \vdots & \qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad \vdots\\\\ u''(x_n) + u'(x_n) & \approx \frac{y_{n+1} - 2y_n + y_{n-1}}{h^2} + \frac{y_{n+1} - y_{n-1} }{2h} = \frac{(2+h)y_{n+1} - 4y_n + (2-h)y_{n-1}}{2h^2} = f(x_n) \end{align} $$ \begin{pmatrix} 1 & & & & & \\ (2-h) & -4 & (h+2) & & &\\ 0 & (2-h) & -4 & (h+2) &\\ 0 & 0 & (2-h) & -4 & (h+2)&\\ & \ddots & \ddots & \ddots & \ddots & \ddots &\\ & & & \ddots(2-h) & -4 & (h+2\\ & & & & & \\ & & & & & & 1\end{pmatrix} \begin{pmatrix} y_0 \\ y_1 \\y_3 \\ \vdots \\ y_n \end{pmatrix} = \begin{pmatrix} u_\alpha \\ \\ 2h^2f(x_1) \\ \\ 2h^2f(x_2) \\\\ \vdots \\ u_\beta \end{pmatrix} $$