數值線性代數中，逐次超鬆弛（successive overrelaxation，SOR）迭代法是高斯 賽德爾迭代的一種變體，用於求解線性方程組。類似方法也可用於任何緩慢收斂的迭代過程。 SOR 迭代法由 David M Young Jr 和 Stanley P Frankel 在 1950 年同時獨立提出，目的是在計算機上自動求解線性方程組。之前，人們已經為計算員的計算開發過超鬆弛法，如路易斯弗萊理查德森的方法以及 R V Southwell 開發的方法。但這些方法需要一定專業知識確保求解的收斂，不適用於計算機程式設計。David M Young Jr 的論文對這些方面進行了探討。 形式化 給定 n 個線性方程組成的方系統： Amathbf x mathbf b 其中 Abegin bmatrix a_11 a_12 cdots a_1n a_21 a_22 cdots a_2n vdots vdots ddots vdots a_n1 a_n2 cdots a_nn end bmatrix qquad mathbf x begin bmatrix x_1 x_2 vdots x_n end bmatrix qquad mathbf b begin bmatrix b_1 b_2 vdots b_n end bmatrix 則 A 可分解為對角矩陣 D、嚴格上下三角矩陣 U、L： ADLU 其中 D begin bmatrix a_11 0 cdots 0 0 a_22 cdots 0 vdots vdots ddots vdots 0 0 cdots a_nn end bmatrix quad L begin bmatrix 0 0 cdots 0 a_21 0 cdots 0 vdots vdots ddots vdots a_n1 a_n2 cdots 0 end bmatrix quad U begin bmatrix 0 a_12 cdots a_1n 0 0 cdots a_2n vdots vdots ddots vdots 0 0 cdots 0 end bmatrix 線性方程組可重寫為 Domega L mathbf x omega mathbf b omega U omega1 D mathbf x 其中 omega1 是常數，稱作鬆弛因子（relaxation factor）。 逐次超鬆弛迭代法可以透過迭代逼近 x 的精確解，可分析地寫作 mathbf xk1 Domega L1 big omega mathbf b omega U omega1 D mathbf xkbigL_omega mathbf xkmathbf c 其中 mathbf xk 是 mathbf x 的第 k 次迭代值，mathbf xk1 是 mathbf x 下一次迭代所得的值。 利用 Domega L 的三角形，可用向前替換法依次計算 mathbf xk1 的元素： xk1_i 1omega xk_i frac omegaa_ii left b_i sum_ji a_ij xk_j rightquad i12ldotsn 收斂性 鬆弛因子 omega 的選擇並不容易，取決於係數矩陣的性質。1947 年，亞歷山大馬雅科維奇奧斯特洛夫斯基證明，若 A 是對稱正定矩陣，則 forall 0omega2 rho L_omega1。因此，迭代過程將收斂，但更高的收斂速度更有價值。 收斂速度 SOR 法的收斂速度可透過分析得出。假設 鬆弛因子適當： omega in 02 雅可比法迭代矩陣 C_text Jac ID1 A 只有實特徵值 雅可比法收斂： mu rho C_text Jac 1 矩陣分解 ADLU 滿足 forall zinmathbb Csetminus0 lambdainmathbb C operatorname detlambda D zL tfrac 1z U operatorname detlambda D L U 則收斂速度可表為 rho C_omega begin cases frac 14 left omega mu sqrt omega2 mu24 omega1 right2 0 omega leq omega_text opt omega 1 omega_text opt omega 2 end cases 最優鬆弛因子是 omega_text opt 1 left frac mu1sqrt 1mu2 right2 1 frac mu24 O mu3 特別地，omega 1 時 SOR 法即退化為高斯 賽德爾迭代，有 rho C_omegamu2rho C_text Jac2。 對最優的 omega，有 rho C_omegafrac 1sqrt 1mu21sqrt 1mu2 frac mu24 O mu3，表明 SOR 法的效率約是高斯 賽德爾迭代的 4 倍。 最後一條假設對三對角矩陣也滿足，因為 Z lambda D L U Z1lambda D zL tfrac 1z U 對對角陣 Z，其元素 Z_iizi1、 operatorname detlambda D L U operatorname detZ lambda D L U Z1 。 演算法 由於此演算法中，元素可在迭代過程中被覆蓋，所以只需一個儲存向量，不需要向量索引。 輸入： 輸出： 選擇初始解 repeat until convergence for from 1 until do set to 0 for from 1 until do if then set to end if end loop set to end loop check if convergence is reached end repeat 注意：1omegaphi_i frac omegaa_ii b_i sigma 也可寫作 phi_i omega left frac b_i sigmaa_ii phi_iright，這樣每次外層 for 迴圈可以省去一次乘法。 例子 解線性方程組 begin align 4x_1 x_2 6x_3 0x_4 2 5x_1 4x_2 10x_3 8x_4 21 0x_1 9x_2 4x_3 2x_4 12 1x_1 0x_2 7x_3 5x_4 6 end align 擇鬆弛因子 omega 05 與初始解 phi 0 0 0 0。由 SOR 演算法可得下表，在 38 步取得精確解。 迭代 x_1 x_2 x_3 x_4 1 025 278125 16289062 05152344 2 12490234 22448974 19687712 09108547 3 2070478 16696789 15904881 076172125 37 29999998 20 20 10 38 30 20 20 10 用 Common Lisp 的簡單實現： 預設浮點格式設為 longfloat，以確保在更大範圍數字上正確執行 setf readdefaultfloatformat longfloat defparameter MAXIMUMNUMBEROFITERATIONS 100 The number of iterations beyond which the algorithm should cease its operation regardless of its current solution A higher number of iterations might provide a more accurate result but imposes higher performance requirements declaim type integer 0 MAXIMUMNUMBEROFITERATIONS defun geterrors computedsolution exactsolution For each component of the COMPUTEDSOLUTION vector retrieves its error with respect to the expected EXACTSOLUTION vector returning a vector of error values While both input vectors should be equal in size this condition is not checked and the shortest of the twain determines the output vectors number of elements The established formula is the following Let resultVectorSize min computedSolutionlength exactSolutionlength Let resultVector new vector of resultVectorSize For i from 0 to resultVectorSize 1 resultVector i exactSolution i computedSolution i Return resultVector declare type vector number computedsolution declare type vector number exactsolution map vector number exactsolution computedsolution defun isconvergent errors key errortolerance 0001 Checks whether the convergence is reached with respect to the ERRORS vector which registers the discrepancy betwixt the computed and the exact solution vector The convergence is fulfilled if and only if each absolute error component is less than or equal to the ERRORTOLERANCE that is For all e in ERRORS it holds abs e errorTolerance declare type vector number errors declare type number errortolerance flet errorisacceptable error declare type number error abs error errortolerance every errorisacceptable errors defun makezerovector size Creates and returns a vector of the SIZE with all elements set to 0 declare type integer 0 size makearray size initialelement 00 elementtype number defun successiveoverrelaxation A b omega key phi makezerovector length b convergencecheck lambda iteration phi declare ignore phi iteration MAXIMUMNUMBEROFITERATIONS Implements the successive overrelaxation SOR method applied upon the linear equations defined by the matrix A and the righthand side vector B employing the relaxation factor OMEGA returning the calculated solution vector The first algorithm step the choice of an initial guess PHI is represented by the optional keyword parameter PHI which defaults to a zerovector of the same structure as B If supplied this vector will be destructively modified In any case the PHI vector constitutes the functions result value The terminating condition is implemented by the CONVERGENCECHECK an optional predicate lambda iteration phi generalizedboolean which returns T signifying the immediate termination upon achieving convergence or NIL signaling continuant operation otherwise In its default configuration the CONVERGENCECHECK simply abides the iterations ascension to the MAXIMUMNUMBEROFITERATIONS ignoring the achieved accuracy of the vector PHI declare type array number A declare type vector number b declare type number omega declare type vector number phi declare type function integer 1 vector number convergencecheck let n arraydimension A 0 declare type integer 0 n loop for iteration from 1 by 1 do loop for i from 0 below n by 1 do let rho 0 declare type number rho loop for j from 0 below n by 1 do when j i let a ij aref A i j phi j aref phi j incf rho a ij phi j setf aref phi i 1 omega aref phi i omega aref A i i aref b i rho format T d solution a iteration phi Check if convergence is reached when funcall convergencecheck iteration phi return the vector number phi Summon the function with the exemplary parameters let A makearray list 4 4 initialcontents 4 1 6 0 5 4 10 8 0 9 4 2 1 0 7 5 b vector 2 21 12 6 omega 05 exactsolution vector 3 2 2 1 successiveoverrelaxation A b omega convergencecheck lambda iteration phi declare type integer 0 iteration declare type vector number phi let errors geterrors phi exactsolution declare type vector number errors format T d errors a iteration errors or isconvergent errors errortolerance 00 iteration MAXIMUMNUMBEROFITERATIONS 上述虛擬碼的簡單 Python 實現。 import numpy as np from scipy import linalg def sor_solver A b omega initial_guess convergence_criteria This is an implementation of the pseudocode provided in the Wikipedia article Arguments A nxn numpy matrix b n dimensional numpy vector omega relaxation factor initial_guess An initial solution guess for the solver to start with convergence_criteria The maximum discrepancy acceptable to regard the current solution as fitting Returns phi solution vector of dimension n step 0 phi initial_guess residual linalgnorm A phi b Initial residual while residual convergence_criteria for i in range Ashape 0 sigma 0 for j in range Ashape 1 if j i sigma A i j phi j phi i 1 omega phi i omega A i i b i sigma residual linalgnorm A phi b step 1 print Step Residual 106gformat step residual return phi An example case that mirrors the one in the Wikipedia article residual_convergence 1e8 omega 05 Relaxation factor A nparray 4 1 6 0 5 4 10 8 0 9 4 2 1 0 7 5 b nparray 2 21 12 6 initial_guess npzeros 4 phi sor_solver A b omega initial_guess residual_convergence print phi 對稱逐次超鬆弛 對對稱矩陣 A，其中 ULT 有對稱逐次超鬆弛迭代法（SSOR）： Pleft frac DomegaLrightfrac omega2omega D1left frac DomegaUright 迭代法為 mathbf xk1mathbf xkgammak P1Amathbf xkmathbf b k ge 0 SOR 與 SSOR 法都來自 David M Young Jr 其他應用 任何迭代法都可應用相似技巧。若原迭代的形式為 x_n1f x_n 則可將其改為 xmathrm SOR_n11omega xmathrm SOR_nomega f xmathrm SOR_n 但若將 x 視作完整向量，則上述解線性方程組的公式不是這種公式的特例。此公式基礎上，計算下一個向量的公式是 mathbf xk1 1omegamathbf xk omega L_1 mathbf b Umathbf xk 其中 L_ L D。omega1 用於加快收斂速度，omega1 可使發散的迭代收斂或加快過調（overshoot）過程的收斂。有多種方法可根據觀察到的收斂過程行為，自適應地調整鬆弛因子 omega。這些方法通常只對一部分問題有效。 另見 雅可比法 置信傳播 矩陣分裂 註釋 參考文獻 Abraham Berman Robert J Plemmons Nonnegative Matrices in the Mathematical Sciences 1994 SIAM A Hadjidimos Successive overrelaxation SOR and related methods Journal of Computational and Applied Mathematics 123 2000 177199 Yousef Saad Iterative Methods for Sparse Linear Systems 1st edition PWS 1996 Netlibs copy of Templates for the Solution of Linear Systems by Barrett et al Richard S Varga 2002 Matrix Iterative Analysis Second ed of 1962 Prentice Hall edition SpringerVerlag David M Young Jr Iterative Solution of Large Linear Systems Academic Press 1971 reprinted by Dover 2003 外部連結 Module for the SOR Method Tridiagonal linear system solver based on SOR in C Category 數值線性代數 Category 帶有虛擬碼示例的條目 Category 帶有 Python 程式碼示例的條目