⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tdma.m

📁 本代码为黄华江编著《实用化工计算机模拟—MATLAB在化学工程中的应用》的配套车程序
💻 M
字号:
function X = TDMA(A,D,C,B)
% Tridiagonal Matrix Algorithm(三对角阵算法)
%
% Function: to solve the Tridiagonal system CX=B, where C is a Tridiagonal matrix
%
% Input      - A is the subdiagonal of the coefficient matrix
%               - D is the main diagonal of the coefficient matrix
%               - C is the superdiagonal of the coefficient matrix        
%               - B is the constant vector of the linear system
% Output   - X is the sulution vector

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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -