My test result is the same as Tim's and Alex's. My A matrix is only 20*20 and is strictly diagonally dominant tridiagonal.
It took "thomas(A,B)" 62.7 seconds to complete 4000 time-steps, while "A\B" used only 4.5 seconds.
Excellent algorithm. I tested it on 2000x2000 matrix, it's 10 times faster than back slash and 5 times faster than inv(), on 2.0G Intel Duo Core, 1G ram, on Matlab 8a. (1.2 seconds for thomas, 6.5 s for inv(), and 13.5 for /).
For small matrix, say 100x100, these three are comparable.
I though Tim was right and trusted back slash. But it's not the case for me.
I don't know what kind of sparse matrices Tim and Alex talking about that back slash runs faster for. I would say the 3-diagonal is already sparse and is encounter often in solving pdes.
This function is superseded by the tridiagonal solver that is now built into MATLAB (x=A\b). For x=thomas(A,b) where A is sparse and tridiagonal, x=A\b is up to 25,000 times (!) faster than this code. For x=thomas(amain,aup,alo,b), this function is about 30 times slower than x=A\b.
So the only reason for this code is to illustrate the algorithm - for which its still useful. But don't expect to get great performance from it compared to x=A\b in MATLAB 7.5
Comment only