Print content
Dirichlet boundary problem
PMiKNoM seminars - class 5
Introduction
- Second Fick's Law for stationary states and other examples of boundary problems.
The general equation
There are many applications, that require solution of second order differential equation with boundary conditions expressed by known values of the function at the boundary points (optionally its derivatives or combination of function value and derivative). An example of such problem is given as:
$$
\left\{ \begin{array}{l}
-\alpha(x) u \text{"} (x) + \beta(x) u \text{'} (x) + \gamma(x)u(x) = f(x) \\
u(x_L)=u_L \\
u(x_R)=u_R
\end{array} \right.
$$
where: `u(x)=?` is unknown function, specified in a range `[x_L,x_R]`; `\alpha,\beta,\gamma` and `f` are known functions; `u_L` and `u_R` are constant values on the left and right boundary, respectively.
The problem defined with the above equations is known as Dirichlet boundary problem. The important thing is, that the values of the function `u(x)` at the boundaries are given.
Solution of Dirichlet boundary problem:
General equation:
- Divide the range `[x_L,x_R]` into `n+1` equal sections. Distance between each two points `x_i` and `x_{i+1}` equals `h=(x_R-x_L)/(n+1)`.
-
Write the general equation for each `i`-th discrete point:
`-\alpha(x_i) u \text{"} (x_i) + \beta(x_i) u \text{'} (x_i) + \gamma(x_i)u(x_i) = f(x_i)`
-
Substitute the first and second derivative using finite differences:
` u \text{'}(x_i) = \frac{u_{i+1}-u_{i-1}}{2h} `` u \text{"}(x_i) = \frac{u_{i+1}-2u_i+u_{i-1}}{h^2} `
-
You obtain:
`-\alpha(x_i) \frac{u_{i+1}-2u_i+u_{i-1}}{h^2} + \beta(x_i) \frac{u_{i+1}-u_{i-1}}{2h} + \gamma(x_i)u(x_i) = f(x_i)`
-
Multiply both sides by `h^2` and rearrange the equation:
`u_{i-1} ( - \alpha(x_i) - \frac{h}{2} \beta(x_i) ) + u_i (2 \alpha(x_i) + h^2 \gamma(x_i)) + u_{i+1} ( - \alpha(x_i) + \frac{h}{2} \beta(x_i) ) = h^2 f(x_i)`
-
Rewrite the equation above, substituting `i=1`:
`u_0 ( - \alpha(x_1) - \frac{h}{2} \beta(x_1) ) + u_1 (2 \alpha(x_1) + h^2 \gamma(x_1)) + u_2 ( - \alpha(x_1) + \frac{h}{2} \beta(x_1) ) = h^2 f(x_1)`
-
Having `u_0 = u(a) = u_L`, one can move it to the right-hand side of the equation:
`u_1 (2 \alpha(x_1) + h^2 \gamma(x_1)) + u_{2} ( - \alpha(x_1) + \frac{h}{2} \beta(x_1) ) = h^2 f(x_1) + u_L ( \alpha(x_1) + \frac{h}{2} \beta(x_1) )`
-
We perform similar substitution for the point `i=n`, obtaining:
`u_{n-1} ( - \alpha(x_n) - \frac{h}{2} \beta(x_n) ) + u_n (2 \alpha(x_n) + h^2 \gamma(x_n)) + u_{n+1} ( - \alpha(x_n) + \frac{h}{2} \beta(x_n) ) = h^2 f(x_n)`
-
Having `u_{n+1} = u(b) = u_R`, one can move it to the right-hand side of the equation:
`u_{n-1} ( - \alpha(x_n) - \frac{h}{2} \beta(x_n) ) + u_n (2 \alpha(x_n) + h^2 \gamma(x_n)) = h^2 f(x_n) + u_R ( \alpha(x_n) - \frac{h}{2} \beta(x_n) )`
-
The set of equations:
$$ \left\{ \begin{array}{l} u_1 (2 \alpha(x_1) + h^2 \gamma(x_1)) + u_{2} ( - \alpha(x_1) + \frac{h}{2} \beta(x_1) ) = h^2 f(x_1) + u_L ( \alpha(x_1) + \frac{h}{2} \beta(x_1) ) \\ u_{i-1} ( - \alpha(x_i) - \frac{h}{2} \beta(x_i) ) + u_i (2 \alpha(x_i) + h^2 \gamma(x_i)) + u_{i+1} ( - \alpha(x_i) + \frac{h}{2} \beta(x_i) ) = h^2 f(x_i) \text{, for } i=2..n-1 \\ u_{n-1} ( - \alpha(x_n) - \frac{h}{2} \beta(x_n) ) + u_n (2 \alpha(x_n) + h^2 \gamma(x_n)) = h^2 f(x_n) + u_R ( \alpha(x_n) - \frac{h}{2} \beta(x_n) ) \end{array} \right. $$forms the tri-diagonal matrix:$$ \left\{ \begin{array}{l} d_1 u_1 + c_1 u_2 = b_1 \\ a_{i-1} u_{i-1} + d_i u_i + c_i u_{i+1} = b_i \text{, for } i=2..n-1\\ a_{n-1} u_{n-1} + d_n u_n = b_n \end{array} \right. $$
- Hence, in order to solve the problem, first one has to assign values to the tri-diagonal matrix, i.e. `d_1 = (2 \alpha(x_1) + h^2 \gamma(x_1))`, `c_1 = ( - \alpha(x_1) + \frac{h}{2} \beta(x_1) )`, `b_1 = h^2 f(x_1) + u_L ( \alpha(x_1) + \frac{h}{2} \beta(x_1) )`, and so on...
- Solution of the tri-diagonal matrix is presented in class 4.
Boundaries:
Tri-diagonal matrix:
Dirichlet boundary problem - program's algorithm
- Declare global constants `xL = 0`, `xR = 1`, `uL = 0`, `uR = 0` and `n = 100`.
- Define functions: `\alpha(x)=x^2`, `\beta(x) = x`, `\gamma(x)=1` and `f(x)=x \cdot (x-2)`.
- Begin the main procedure with declarations of variable `h` and arrays `a(1 \text{ to } n-1)`, `d(1 \text{ to } n)`, `c(1 \text{ to } n-1)`, `b(1 \text{ to } n)` and `x(0 \text{ to } n+1)`.
- Calculate the step value `h`.
- Assign the location of all `x(i)` points, i.e. `x(i)=i \cdot h`. (remember about the boundary points)
- Assign the values to arrays `a`, `b`, `c` and `d` (using 'for' loops).
- Write the set of instructions that solves the tri-diagonal matrix (loop + instruction + loop).
- Display results.
Additional materials:
- R. Filipek, K. Szyszkiewicz-Warzecha "Metody Matematyczne dla Ceramików", pages 128-147.