backsubold.m

来自「计算水声传播的快速场(FFP)程序」· M 代码 · 共 32 行

M
32
字号
function x = backsub( N, mults, d, e, b )
% x = backsub( N, mults, d, e, b )
%
% Based on TINVIT in EISPACK
% performs back-substitution for a symmetric tridiagonal linear system
% N is the order of the matrix
% d contains the diagonal of the upper triangular matrix
% e contains the upper diagonal
% m contains the multipliers used during forward elimination
% b contains the right hand side (Ax=b)
% the answer is returned in vector b
%
% Michael B. Porter 7/1/85

% make sure input vectors are column vectors
d = d(:);
e = e(:);
b = b(:);

% Forward elimination
for I = 2 : N
    b( I ) = b( I ) - mults( I-1 ) * b( I - 1 );
end

% Back-substitution (result in b)
x( N ) = b( N ) / d( N );
if ( N >= 2 )
    for I = N - 1 : -1 : 1
        x( I ) = ( b( I ) - e( I + 1 ) * x( I + 1 ) ) / d( I );
    end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?