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.430357In 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\fproduced 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.430357which 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.
In the computing lab we solved the test problem where
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.