tridiag_lu_sl.m

来自「LU decomposition routines in matlab」· M 代码 · 共 50 行

M
50
字号
function [b, iflag] = tridiag_lu_sl( c, d, e, b);%% TRIDIAG_LU_SL solves a tridiagonal linear system A x = b,%    using the LU decomposition of A computed by TRIDIAG_LU.%% Usage%       [b, iflag] = tridiag_lu_sl( c, d, e, b)%% input:%        d, e contain the LU factors in compact form%               of A as computed by tridiag_lu%%        b      right hand side vector% output:
   %%        b  overwritten with the solution of the system if iflag = 0.%%%        iflag: error flag%               iflag = 0  solution could be computed and is%                          stored in b%               iflag = 1  dimension of b, and A are not compatible%               iflag > 1  zero diagonal element detected in step iflag+1%%%% Matthias Heinkenschloss% Feb 6, 2001iflag = 0;% get size of A and check dimensionsn    = size(d(:),1);if ( n ~= size(b(:),1) )   iflag = 1;   returnend% solve L y = b (overwrite b with the solution)for i = 2:n   b(i) = b(i) - c(i-1)*b(i-1);end% solve U x = y (overwrite b with the solution)b(n) = b(n) / d(n);for i = n-1:-1:1   b(i) = (b(i) - e(i)*b(i+1)) / d(i);end

⌨️ 快捷键说明

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