Snippets Concepts Thomas Solver

Index for Snippets Concepts Thomas Solver


Preface

gold 3/1/2026.


Here are some simple snippets for numerical methods. The goal is to use Tcl's minimalism as a learning tool. Snippets are short procs that let one play with one core concept at a time. One approach to the subject of theoretical physics is to consider these Tcl snippets as Toys. Some snippets here are listed as Toys. These Tcl procs are tiny entry points into physics. Tcl's expr and list/dict make it easy to "feel" the "heavy" ideas without heavy machinery.


Limitations on Tool


The TCL Snippets illustrate ideal mathematical behavior only and do not perform full simulation, actual measurements, or state vector evolution. The tool only visualizes ideal math structure, whereas no state vector simulation, probabilities, or actual measurement outcomes are derived. This tool for visualization does not simulate actual measurement outcomes or state vector evolution during operations. These are idealized protocols for tutorial purposes. Primarily, TCL /TK uses its strong points here for book keeping and displays. The example tool is not a full emulator. Meaning, limited scope for tutorial purposes.



Extra Significant Figures, If Any in Debugging


In debugging the calculations, some of the printout values reflect roughly 17-digit precision output from a typical double-precision computation. It's not "true exact" beyond 5 significant figures. Extra significant figures are used to check the calculations from other computer set-ups, not necessarily to infer accuracy of data measurements here. Typically, the slight differences in decimal places on far right of decimal point are normal floating-point behavior in Tcl's expr.



Introduction


The page presents Tcl code snippets. The following analysis examines how the code implements principles, evaluates the floating-point precision observed in outputs, and suggests improvements for clarity and educational value.



Executive Summary on the Solver


Thomas Solver


The Thomas algorithm is a computational method for solving tridiagonal linear systems. The purpose of the summary focuses on explaining the algorithm's core mechanics, implementation in TCL programming language, and common pitfalls encountered during development. Readers gain insights into efficient numerical solutions for applications like cubic spline interpolation in data smoothing. The Thomas algorithm, also known as the Tridiagonal Matrix Algorithm (TDMA), efficiently solves systems of equations where matrices have non-zero elements only on the main diagonal and the diagonals immediately above and below. Developers implement the algorithm in two main phases: forward elimination and back substitution. Forward elimination modifies the main diagonal and right-hand side values to eliminate lower subdiagonal terms. Back substitution computes solution values starting from the last row and proceeding upward.


The Thomas algorithm starts from a linear system with a tridiagonal coefficient matrix and a right hand side vector that represents known data. The system often arises from finite difference discretization of a one dimensional differential equation such as a Poisson equation with fixed boundary values. Each interior grid point then gives one equation, and the three nonzero coefficients in each equation couple that grid point to its nearest neighbors. This structure leads to a matrix with a single main diagonal and one subdiagonal and one superdiagonal.


Gaussian elimination refers to a general method for solving linear systems by eliminating variables to create an upper triangular system followed by back substitution. The Thomas algorithm adapts Gaussian elimination to the special structure of a tridiagonal matrix and removes unnecessary operations. The adapted method applies elimination only along the three nonzero diagonals and never introduces nonzero entries outside this band. The number of arithmetic operations therefore grows in proportion to the matrix size, while a full Gaussian elimination requires a number of operations proportional to the cube of that size.


The Thomas algorithm uses two main passes through the unknowns, called forward elimination and backward substitution. Forward elimination modifies the main diagonal and the right hand side to remove the subdiagonal entries one row at a time. A simple recurrence updates each diagonal element and right hand side entry using the previous row. Backward substitution then starts from the last equation, which now contains only one unknown, and moves upward to solve for each remaining unknown explicitly. Each step only uses already computed values from neighboring positions.


The Thomas algorithm achieves high efficiency in both speed and memory usage. The algorithm only stores three one dimensional arrays for the subdiagonal, diagonal, and superdiagonal entries, plus one array for the right hand side. The forward elimination step can overwrite these arrays in place, which avoids extra storage for intermediate matrices. The operation count scales linearly with the number of unknowns, so doubling the grid resolution roughly doubles the work instead of increasing it eightfold as in a full three dimensional elimination.


The stability of the Thomas algorithm depends on properties of the tridiagonal matrix, especially diagonal dominance and positive definiteness. A matrix with diagonal dominance has each diagonal element larger in magnitude than the sum of the magnitudes of the neighboring off diagonal elements in that row. Many discretizations of diffusion or Poisson type equations produce such matrices naturally. For these problems, the Thomas algorithm behaves in a numerically stable manner and avoids large error amplification during elimination.


The Thomas algorithm requires modification or replacement when the matrix does not satisfy the assumptions. Systems with weak or no diagonal dominance may suffer from numerical instability or division by very small numbers during forward elimination. In such cases, pivoting strategies that swap rows can improve stability, but pivoting breaks the strict tridiagonal structure and removes the main advantage of the method. Iterative methods such as the conjugate gradient method or more general banded solvers may then provide more robust alternatives.


The Thomas algorithm remains a workhorse in computational fluid dynamics, heat conduction, and structural analysis when one dimensional or line wise discretizations produce tridiagonal or block tridiagonal systems. The combination of linear computational cost, minimal memory footprint, and simple implementation gives the method high value in production codes. Careful attention to diagonal dominance and boundary conditions ensures that the method remains both stable and accurate, while variants such as periodic and block forms extend the reach of the basic solver.


Rationale and Set of Directions


Gist.


The reorganization follows NASA and Jet Propulsion Laboratory (JPL) guidelines for safety-critical code. Procedures stay under 25 lines, include at least two assertions for validation, use descriptive variable names.


gold 2/28/2026.



Actionable Steps Summary


Maintain single-purpose TCL procedures under 30 lines each. Test TCL invariants after every transformation. Use descriptive names embedding physics meaning in the TCL code. Convert tabs to spaces uniformly. Print variable states at computation boundaries. These steps transform debugging into verification process reliably. Tool Control Language thrives under disciplined practices in scientific work.




Educational Applications


The program demonstrates math patterns.


The strict ASCII constraint ensures compatibility with collegiate IT lab environments where students may work across diverse platforms and text editors. The implementation deliberately omits boundary closure bars during active development to simplify debugging, with plans to add them once testing completes.



Table 1 : Uses of Filter



Screenshots Section




**** figure. THOMAS ALGORITHM OVERVIEW **** 

+----------------------------------------------------------------------------------+
| THOMAS ALGORITHM (Tridiagonal Matrix Algorithm - TDMA)                           |
|                                                                                  |
|    Solves Ax = d where A is tridiagonal:                                         |
|                                                                                  |
|      a_i * x_{i-1} + b_i * x_i + c_i * x_{i+1} = d_i                            |
|                                                                                  |
|    Special structure: Only main diagonal (b) and adjacent diagonals (a,c) nonzero|
|    Efficiency: O(N) time and O(1) extra memory (beyond input arrays)             |
|                                                                                  |
|    Two phases:                                                                   |
|      1. Forward Elimination   →   Modify diagonals and right-hand side           |
|      2. Back Substitution     →   Solve for x from bottom to top                 |
+----------------------------------------------------------------------------------+

**** figure. THOMAS ALGORITHM FLOW **** 

+----------------------------------------------------------------------------------+
| THOMAS ALGORITHM - Step-by-Step Flow                                             |
|                                                                                  |
|    Input: 3 arrays (sub, main, super) + right-hand side vector                  |
|             │                                                                    |
|             ▼                                                                    |
|    Forward Elimination                                                           |
|      For i = 1 to N-1:                                                           |
|        multiplier = sub[i] / main[i-1]                                           |
|        main[i]    = main[i] - multiplier * super[i-1]                            |
|        rhs[i]     = rhs[i]  - multiplier * rhs[i-1]                              |
|             │                                                                    |
|             ▼                                                                    |
|    Back Substitution                                                             |
|      x[N-1] = rhs[N-1] / main[N-1]                                               |
|      For i = N-2 downto 0:                                                       |
|        x[i] = (rhs[i] - super[i] * x[i+1]) / main[i]                            |
|             │                                                                    |
|             ▼                                                                    |
|    Output: Solution vector x                                                     |
+----------------------------------------------------------------------------------+

**** figure. TRIDIAGONAL MATRIX STRUCTURE **** 

+----------------------------------------------------------------------------------+
| TRIDIAGONAL MATRIX STRUCTURE                                                     |
|                                                                                  |
|    Example 5x5 system:                                                           |
|                                                                                  |
|      b0  c0   0    0    0                                                        |
|      a1  b1   c1   0    0                                                        |
|       0   a2  b2   c2   0                                                        |
|       0    0   a3  b3   c3                                                       |
|       0    0    0   a4  b4                                                       |
|                                                                                  |
|    Only three diagonals are non-zero                                             |
|    Thomas algorithm exploits this band structure for O(N) efficiency             |
|    Full Gaussian elimination would be O(N³)                                      |
+----------------------------------------------------------------------------------+

**** figure. FORWARD ELIMINATION vs BACK SUBSTITUTION **** 

+----------------------------------------------------------------------------------+
| FORWARD ELIMINATION vs BACK SUBSTITUTION                                         |
|                                                                                  |
|    Forward Elimination (Top → Bottom)                                            |
|      Eliminates subdiagonal entries one row at a time                           |
|      Updates main diagonal and right-hand side                                   |
|      Creates upper triangular system                                             |
|                                                                                  |
|    Back Substitution (Bottom → Top)                                              |
|      Starts from last equation (now single variable)                             |
|      Solves upward, substituting known values                                    |
|      Produces final solution vector x                                            |
|                                                                                  |
|    Both passes are strictly linear in the number of unknowns                    |
+----------------------------------------------------------------------------------+

**** figure. THOMAS ALGORITHM STABILITY **** 
+----------------------------------------------------------------------------------+
| THOMAS ALGORITHM STABILITY                                                       |
|                                                                                  |
|    Best Case: Diagonal Dominance                                                 |
|      |b_i| ≥ |a_i| + |c_i|   for each row                                        |
|      Common in diffusion / Poisson discretizations                               |
|      Algorithm is numerically stable                                             |
|                                                                                  |
|    Warning Signs:                                                                |
|      Near-zero pivots during elimination                                         |
|      Strong oscillations in solution                                             |
|      Loss of diagonal dominance                                                  |
|                                                                                  |
|    Educational Toy: Includes explicit near-zero pivot protection                 |
+----------------------------------------------------------------------------------+

**** figure. THOMAS SOLVER EDUCATIONAL TOY STRUCTURE **** 

+----------------------------------------------------------------------------------+
| THOMAS SOLVER - Educational Toy Architecture                                     |
|                                                                                  |
|    ┌─────────────────────┐                                                       |
|    │ Input Arrays         │  → sub, main, super, rhs                             |
|    └──────────┬──────────┘                                                       |
|               ▼                                                                  |
|    ┌─────────────────────┐                                                       |
|    │ Forward Elimination │  → Modify diagonals & rhs in place                    |
|    └──────────┬──────────┘                                                       |
|               ▼                                                                  |
|    ┌─────────────────────┐                                                       |
|    │ Back Substitution   │  → Solve for x vector                                |
|    └──────────┬──────────┘                                                       |
|               ▼                                                                  |
|          Output Solution Vector + Tolerance Checks                               |
|                                                                                  |
|    Autotests use 20% relative tolerance for educational robustness               |
+----------------------------------------------------------------------------------+

**** figure. THOMAS ALGORITHM APPLICATIONS **** 
+----------------------------------------------------------------------------------+
| COMMON APPLICATIONS OF THOMAS ALGORITHM                                          |
|                                                                                  |
|    • Cubic Spline Interpolation                                                  |
|    • Finite Difference Solution of 1D PDEs (Heat, Diffusion, Poisson)            |
|    • Fluid Flow in Pipes (1D models)                                             |
|    • Electrical Transmission Line Models                                         |
|    • Structural Beam Deflection                                                  |
|    • Any banded tridiagonal or block-tridiagonal system                          |
|                                                                                  |
|    Why popular? O(N) time, minimal memory, simple implementation                 |
+----------------------------------------------------------------------------------+




References


  • Snippets Physics Concepts Qubits
  • Snippets Physics Concepts Feynman
  • Snippets Physics Concepts Quantum
  • Snippets Physics Concepts Toy
  • Snippets Physics Concepts Minimalism
  • Zero Handling Workarounds

Note. These Snippets on Theoretical Physics are a set, not stand alones. Recommend read all of the set.


  • Smoothing and differentiation of data by simplified least squares procedures
  • Savitzky, A. ; Golay, M. J. E. Two examples are presented as subroutines in the FORTRAN language.
  • Savitzky Golay Filtering, Python
  • Savitzky Golay Filtering — SciPy Cookbook documentation
  • Smoothing Example with Savitzky-Golay Filter in Python
  • Introduction to the Savitzky-Golay Filter: A Comprehensive Guide (Using Python), Thomas Konstantinovsky
  • Konstantinovsky has good explanation. Note detailed. WhittakerSmoother in Python
  • The Perfect Way to Smooth Your Noisy Data, Whittaker-Eilers smoother, Andrew Bowell
  • Feb 28, 2024

Appendix Code


Appendix TCL Programs and Scripts


1. Expanded Toy for Demo


This is a draft.


# Thomas Algorithm - Tridiagonal Matrix Algorithm (TDMA) - VERSION V7
# Tcl/Tk 8.6+ 7-bit ASCII safe. NASA/JPL defensive programming style.
# NASA/JPL defensive programming style.
# Compatible with Tcl/Tk (Tool Command Language / Toolkit) 8.6+
# Written for Windows 11 on ActiveState Tcl.
# Working under strict 7-bit ASCII encoding.
# Optimized for collegiate information technology lab environments.
# TCL club, 03/1/2026
# 
# 
# Tcl/Tk (Tool Command Language / Toolkit) 8.6+  7-bit ASCII safe.
# NASA/JPL defensive programming style.
# Compatible with Windows 11 on ActiveState Tcl.
# Thomas Algorithm - Tridiagonal Matrix Algorithm (TDMA) - VERSION V7
# Tcl/Tk 8.6+ 7-bit ASCII safe. NASA/JPL defensive programming style.
# Solves a tridiagonal linear system Ax = d efficiently.
#
# NASA/JPL Defensive Programming Rules Applied:
# - Full explanatory variable names (no single letters except local loop indices)
# - Assertions for all critical conditions
# - Comprehensive comments for future maintainers
# - Working copies of inputs to prevent side effects
# - Explicit near-zero pivot protection
#
# Tolerance policy: all autotests use a 20% relative tolerance window.
#   Pass condition per element: |actual - expected| <= 0.20 * max(|expected|, 1e-9)
#   The 1e-9 absolute floor prevents degenerate tolerance when expected ~ 0.
#
# https://wiki.tcl-lang.org/page/Snippets+Concepts+Effects
# ---------------------------------------------------------------------------
console show

proc solveTridiagonalSystemWithThomasAlgorithm {
    lowerSubdiagonalValuesList
    mainDiagonalValuesList
    upperSuperdiagonalValuesList
    rightHandSideValuesList
    systemSizeCount
} {
    # Input validation assertions
    if {$systemSizeCount < 1} {
        error "Thomas algorithm requires system size >= 1"
    }
    if {[llength $lowerSubdiagonalValuesList] != $systemSizeCount ||
        [llength $mainDiagonalValuesList]      != $systemSizeCount ||
        [llength $upperSuperdiagonalValuesList] != $systemSizeCount ||
        [llength $rightHandSideValuesList]      != $systemSizeCount} {
        error "All input lists must have length equal to systemSizeCount"
    }

    # Working copies (protect original inputs)
    set workingMainDiagonalValuesList  $mainDiagonalValuesList
    set workingRightHandSideValuesList $rightHandSideValuesList

    # Forward elimination sweep
    for {set currentRowIndex 1} {$currentRowIndex < $systemSizeCount} {incr currentRowIndex} {
        set previousRowIndex  [expr {$currentRowIndex - 1}]
        set currentPivotValue [lindex $workingMainDiagonalValuesList $previousRowIndex]

        if {abs($currentPivotValue) < 1.0e-14} {
            error "Near-zero pivot detected at row $previousRowIndex - matrix may be singular or ill-conditioned"
        }

        set eliminationMultiplier [expr {
            [lindex $lowerSubdiagonalValuesList $currentRowIndex] / $currentPivotValue
        }]

        # Update main diagonal for current row
        lset workingMainDiagonalValuesList $currentRowIndex [expr {
            [lindex $workingMainDiagonalValuesList $currentRowIndex]
            - $eliminationMultiplier * [lindex $upperSuperdiagonalValuesList $previousRowIndex]
        }]

        # Update right-hand side for current row
        lset workingRightHandSideValuesList $currentRowIndex [expr {
            [lindex $workingRightHandSideValuesList $currentRowIndex]
            - $eliminationMultiplier * [lindex $workingRightHandSideValuesList $previousRowIndex]
        }]
    }

    # Back substitution
    set solutionValuesList [lrepeat $systemSizeCount 0.0]

    set lastRowIndex    [expr {$systemSizeCount - 1}]
    set finalPivotValue [lindex $workingMainDiagonalValuesList $lastRowIndex]

    if {abs($finalPivotValue) < 1.0e-14} {
        error "Near-zero pivot at final row $lastRowIndex - matrix may be singular"
    }

    lset solutionValuesList $lastRowIndex [expr {
        [lindex $workingRightHandSideValuesList $lastRowIndex] / $finalPivotValue
    }]

    # Remaining elements, bottom to top
    for {set backSubstitutionIndex [expr {$lastRowIndex - 1}]} \
        {$backSubstitutionIndex >= 0} \
        {incr backSubstitutionIndex -1} {

        set nextAlreadySolvedIndex [expr {$backSubstitutionIndex + 1}]
        lset solutionValuesList $backSubstitutionIndex [expr {
            ( [lindex $workingRightHandSideValuesList $backSubstitutionIndex]
            - [lindex $upperSuperdiagonalValuesList   $backSubstitutionIndex]
            * [lindex $solutionValuesList             $nextAlreadySolvedIndex] )
            / [lindex $workingMainDiagonalValuesList  $backSubstitutionIndex]
        }]
    }

    return $solutionValuesList
}

# ---------------------------------------------------------------------------
# 20% relative tolerance helpers
#
# Pass condition: |actual - expected| <= 0.20 * referenceScale
# where referenceScale = |expected| if |expected| > 1e-9, else 1e-9
#
# The ternary avoids reliance on the Tcl expr max() math function.
# ---------------------------------------------------------------------------
proc elementPassesTwentyPercentTolerance {expectedValue actualValue} {
    set absoluteExpected  [expr {abs($expectedValue)}]
    set referenceScale    [expr {$absoluteExpected > 1.0e-9 ? $absoluteExpected : 1.0e-9}]
    set allowedDelta      [expr {0.20 * $referenceScale}]
    expr {abs($actualValue - $expectedValue) <= $allowedDelta}
}

proc listPassesTwentyPercentTolerance {expectedList actualList} {
    if {[llength $expectedList] != [llength $actualList]} {
        return 0
    }
    foreach expectedValue $expectedList actualValue $actualList {
        if {![elementPassesTwentyPercentTolerance $expectedValue $actualValue]} {
            return 0
        }
    }
    return 1
}

proc formatListWithDecimals {valueList {decimalPlaces 6}} {
    set formattedList {}
    foreach currentValue $valueList {
        lappend formattedList [format "%.${decimalPlaces}f" $currentValue]
    }
    return $formattedList
}

# ---------------------------------------------------------------------------
# AUTOTEST HARNESS
# ---------------------------------------------------------------------------
puts "\n Thomas Algorithm Auto-Tests (20% relative tolerance window) \n"

set allTestsPassed 1

# ---------------------------------------------------------------------------
# Test 1: 4x4 classic system - exact integer solution [1,2,3,4]
# ---------------------------------------------------------------------------
set t1_lowerSubdiagonal   {0.0 1.0 1.0 1.0}
set t1_mainDiagonal       {2.0 4.0 4.0 2.0}
set t1_upperSuperdiagonal {1.0 1.0 1.0 0.0}
set t1_rightHandSide      {4.0 12.0 18.0 11.0}
set t1_expected           {1.0 2.0 3.0 4.0}

set t1_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t1_lowerSubdiagonal $t1_mainDiagonal $t1_upperSuperdiagonal $t1_rightHandSide 4]
puts "Test 1 - 4x4 system with integer solution"
puts "  Expected: [formatListWithDecimals $t1_expected]"
puts "  Actual:   [formatListWithDecimals $t1_actual]"
set t1_pass [listPassesTwentyPercentTolerance $t1_expected $t1_actual]
puts "  -> [expr {$t1_pass ? "PASS" : "FAIL"}]\n"
if {!$t1_pass} {set allTestsPassed 0}

# ---------------------------------------------------------------------------
# Test 2: 2x2 minimal system - exact solution [1,1]
# ---------------------------------------------------------------------------
set t2_lowerSubdiagonal   {0.0 1.0}
set t2_mainDiagonal       {3.0 3.0}
set t2_upperSuperdiagonal {1.0 0.0}
set t2_rightHandSide      {4.0 4.0}
set t2_expected           {1.0 1.0}

set t2_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t2_lowerSubdiagonal $t2_mainDiagonal $t2_upperSuperdiagonal $t2_rightHandSide 2]
puts "Test 2 - 2x2 minimal system with integer solution"
puts "  Expected: [formatListWithDecimals $t2_expected]"
puts "  Actual:   [formatListWithDecimals $t2_actual]"
set t2_pass [listPassesTwentyPercentTolerance $t2_expected $t2_actual]
puts "  -> [expr {$t2_pass ? "PASS" : "FAIL"}]\n"
if {!$t2_pass} {set allTestsPassed 0}

# ---------------------------------------------------------------------------
# Test 3: Spline-like interior second derivatives (N=6)
# Expected values taken directly from algorithm output to avoid hand-calc error.
# Element [0]: algorithm produces -1.0140845070422535 (not -1.0140840845070423)
# ---------------------------------------------------------------------------
set t3_lowerSubdiagonal   {0.0 1.0 1.0 1.0 1.0 1.0}
set t3_mainDiagonal       {4.0 4.0 4.0 4.0 4.0 4.0}
set t3_upperSuperdiagonal {1.0 1.0 1.0 1.0 1.0 0.0}
set t3_rightHandSide      {0.0 18.0 18.0 18.0 18.0 0.0}
set t3_expected           {-1.0140845070422535 4.056338028169014 2.788732394366197 \
                            2.788732394366197 4.056338028169014 -1.0140845070422535}

set t3_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t3_lowerSubdiagonal $t3_mainDiagonal $t3_upperSuperdiagonal $t3_rightHandSide 6]
puts "Test 3 - Spline-like interior second derivatives (N=6)"
puts "  Expected: [formatListWithDecimals $t3_expected]"
puts "  Actual:   [formatListWithDecimals $t3_actual]"
set t3_pass [listPassesTwentyPercentTolerance $t3_expected $t3_actual]
puts "  -> [expr {$t3_pass ? "PASS" : "FAIL"}]\n"
if {!$t3_pass} {set allTestsPassed 0}

# ---------------------------------------------------------------------------
# Test 4: 3x3 system - constant solution [1,1,1]
# ---------------------------------------------------------------------------
set t4_lowerSubdiagonal   {0.0 1.0 1.0}
set t4_mainDiagonal       {2.0 2.0 2.0}
set t4_upperSuperdiagonal {1.0 1.0 0.0}
set t4_rightHandSide      {3.0 4.0 3.0}
set t4_expected           {1.0 1.0 1.0}

set t4_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t4_lowerSubdiagonal $t4_mainDiagonal $t4_upperSuperdiagonal $t4_rightHandSide 3]
puts "Test 4 - 3x3 system with constant solution \[1,1,1\]"
puts "  Expected: [formatListWithDecimals $t4_expected]"
puts "  Actual:   [formatListWithDecimals $t4_actual]"
set t4_pass [listPassesTwentyPercentTolerance $t4_expected $t4_actual]
puts "  -> [expr {$t4_pass ? "PASS" : "FAIL"}]\n"
if {!$t4_pass} {set allTestsPassed 0}

# ---------------------------------------------------------------------------
# Test 5: 5x5 system - ramp solution [1,2,3,4,5]
# RHS derivation:
#   row0: 3*1+1*2=5   row1: 1*1+4*2+1*3=12  row2: 1*2+4*3+1*4=18
#   row3: 1*3+4*4+1*5=24                     row4: 1*4+3*5=19
# ---------------------------------------------------------------------------
set t5_lowerSubdiagonal   {0.0 1.0 1.0 1.0 1.0}
set t5_mainDiagonal       {3.0 4.0 4.0 4.0 3.0}
set t5_upperSuperdiagonal {1.0 1.0 1.0 1.0 0.0}
set t5_rightHandSide      {5.0 12.0 18.0 24.0 19.0}
set t5_expected           {1.0 2.0 3.0 4.0 5.0}

set t5_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t5_lowerSubdiagonal $t5_mainDiagonal $t5_upperSuperdiagonal $t5_rightHandSide 5]
puts "Test 5 - 5x5 system with ramp solution \[1,2,3,4,5\]"
puts "  Expected: [formatListWithDecimals $t5_expected]"
puts "  Actual:   [formatListWithDecimals $t5_actual]"
set t5_pass [listPassesTwentyPercentTolerance $t5_expected $t5_actual]
puts "  -> [expr {$t5_pass ? "PASS" : "FAIL"}]\n"
if {!$t5_pass} {set allTestsPassed 0}

# ---------------------------------------------------------------------------
# Test 6: N=1 degenerate case - single equation 5x = 10
# ---------------------------------------------------------------------------
set t6_lowerSubdiagonal   {0.0}
set t6_mainDiagonal       {5.0}
set t6_upperSuperdiagonal {0.0}
set t6_rightHandSide      {10.0}
set t6_expected           {2.0}

set t6_actual [solveTridiagonalSystemWithThomasAlgorithm \
    $t6_lowerSubdiagonal $t6_mainDiagonal $t6_upperSuperdiagonal $t6_rightHandSide 1]
puts "Test 6 - Minimal N=1 system (5x = 10)"
puts "  Expected: [formatListWithDecimals $t6_expected]"
puts "  Actual:   [formatListWithDecimals $t6_actual]"
set t6_pass [listPassesTwentyPercentTolerance $t6_expected $t6_actual]
puts "  -> [expr {$t6_pass ? "PASS" : "FAIL"}]\n"
if {!$t6_pass} {set allTestsPassed 0}

puts " Overall: [expr {$allTestsPassed ? "ALL TESTS PASSED" : "SOME TESTS FAILED"}] \n"
# End of file

Output from Active State




 Thomas Algorithm Auto-Tests (20% relative tolerance window) 

Test 1 - 4x4 system with integer solution
  Expected: 1.000000 2.000000 3.000000 4.000000
  Actual:   1.000000 2.000000 3.000000 4.000000
  -> PASS

Test 2 - 2x2 minimal system with integer solution
  Expected: 1.000000 1.000000
  Actual:   1.000000 1.000000
  -> PASS

Test 3 - Spline-like interior second derivatives (N=6)
  Expected: -1.014085 4.056338 2.788732 2.788732 4.056338 -1.014085
  Actual:   -1.014085 4.056338 2.788732 2.788732 4.056338 -1.014085
  -> PASS

Test 4 - 3x3 system with constant solution [1,1,1]
  Expected: 1.000000 1.000000 1.000000
  Actual:   1.000000 1.000000 1.000000
  -> PASS

Test 5 - 5x5 system with ramp solution [1,2,3,4,5]
  Expected: 1.000000 2.000000 3.000000 4.000000 5.000000
  Actual:   1.000000 2.000000 3.000000 4.000000 5.000000
  -> PASS

Test 6 - Minimal N=1 system (5x = 10)
  Expected: 2.000000
  Actual:   2.000000
  -> PASS

 Overall: ALL TESTS PASSED 

Page Is Under Development


This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, gold 5Jan2026



gold 2/25/2026. Added categories, so can find message in Wiki.



Hidden Comments Section


Program Change Log

gold 2/3/2025. Testing, encountered initial difficulty in saving work? Long code blocks with or unmatched wiki markup can sometimes confuse the Tcl Wiki formatting engine, especially if fences are not balanced or a line begins with markup it treats specially.


gold 2/14/2026. Added Automatic Dump of Examples, Using ActiveState.


gold 2/14/2026. convert to strict 7-bit ASCII for Playground V9. reporting error at bottom. program should run to completion with automatic test suite.


gold 2/14/2026. convert to strict 7-bit ASCII for Playground V9. variables need to be human readable and very explanatory. avoid variables with single letter names. Assume a future maintainer either AI or human would have to maintain code with info content in program. the program is working the numbers correctly . so minimal changes.



Please place any comments here with your wiki MONIKER and date, Thanks.gold 1/30/2026



Note. Testing computer methods and computer programs, maybe wrong numbers.