trisys.m

来自「Matlab numerical methods,examples of mat」· M 代码 · 共 40 行

M
40
字号
function X = trisys(A,D,C,B)
%---------------------------------------------------------------------------
%TRISYS   Solution of a triangular linear system.
%         It is assumed that D and B have dimension n,
%         and that A and C have dimension n-1;
% Sample call
%   X = trisys(A,D,C,B)
% Inputs
%   A   sub diagonal vector
%   D   diagonal vector
%   C   super diagonal vector
%   B   right hand side vector
% Return
%   X   solution vector
%
% NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1995
% To accompany the text:
% NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
% Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
% Prentice Hall, Inc.; USA, Canada, Mexico ISBN 0-13-624990-6
% Prentice Hall, International Editions:   ISBN 0-13-625047-5
% This free software is compliments of the author.
% E-mail address:      in%"mathews@fullerton.edu"
%
% Algorithm 3.t (Tri-Diagonal System).
% Section	3.4, Gaussian Elimination and Pivoting, Page 148
% See exercise 15 on page 159.
%---------------------------------------------------------------------------

n = length(B);
for k = 2:n,
  mult = A(k-1)/D(k-1);
  D(k) = D(k) - mult*C(k-1);
  B(k) = B(k) - mult*B(k-1);
end
X(n) = B(n)/D(n);
for k = (n-1):-1:1,
  X(k) = (B(k) - C(k)*X(k+1))/D(k);
end

⌨️ 快捷键说明

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