Two-point Boundary Value Problems

Our solution of the two-point boundary value problem

y'' + p(x) y' + q(x) = f,   y(α)=A,   y(β)=B

Thomas Algorithm

In class we derived and coded the Thomas algorithm for solving the linear system Ay=f where A is a n by n tridiagonal matrix with the vector a on the diagonal, b on the lower diagonal and c on the upper diagonal. The code for this was tridiag.c which produced the output
input b=1 1 1 1 
input a=4 4 4 4 4 
input c=2 2 2 2 
input f=-1 2 2 2 -1 
b=0.25 0.285714 0.291667 0.292683 
a=4 3.5 3.42857 3.41667 3.41463 
c=2 2 2 2 
solution to Ay=f where A is tridiagonal
with input a on the diagonal, input b lower
diagonal and input c upper diagonal
y=-0.578571 0.657143 -0.025 0.721429 -0.430357 
In order to verify that the Thomas algorithm was working we solved the same problem using GNU Octave. The script
A=[[4 2 0 0 0]
[1 4 2 0 0]
[0 1 4 2 0]
[0 0 1 4 2]
[0 0 0 1 4]]
f=[-1 2 2 2 -1]'
A\f
produced the output
$ octave -q verify.m
A =

   4   2   0   0   0
   1   4   2   0   0
   0   1   4   2   0
   0   0   1   4   2
   0   0   0   1   4

f =

  -1
   2
   2
   2
  -1

ans =

  -0.578571
   0.657143
  -0.025000
   0.721429
  -0.430357
which is the same solution as computed by our program. Note that the diagonals for the matrix are constant so there is a chance that this particular test of correctness would not catch certain indexing errors. Visual inspection of the code also agrees with our mathematically derived algorithm so we procede.

Finite Difference Method

Let h=(β−α)/m and xk=α+kh. We use the finite difference approximation

(yk−1 −2yk +yk+1)/h2 + pk(yk−1 −yk+1)/(2h) + qk yk = fk

for k=1, 2, ..., m−1 with y0=A and ym=B to approximate the solution of the boundary value problem. Since y has m+1 components we set n=m+1 in the Thomas algorithm.

In the computing lab we solved the test problem where

p(x)=cos(x),   q(x)= −(1+x2),   f(x)=2

with boundary conditions y(−2)=−1 and y(2)=−1. The code boundary.c produced output for m=100 that when graphed looks like

While we have not verified this solution is correct, we observe that the output at least looks differentiable.


Last Updated: Sat Nov 8 08:39:49 PST 2014