📄 band_solve.m
字号:
%
% Written by M. Harper Langston - 5/10/00
% harper@cims.nyu.edu
%
% For this sparse LU solver of Ax = b, A has band s.
% For example, the following matrix has band s = 1%% x x 0 0 0 0% x x x 0 0 0% 0 x x x 0 0% 0 0 x x x 0% 0 0 0 x x x% 0 0 0 0 x x%%function [x] = Band_Solve(A,b)
% Here, s is the band number[m,n] = size(A);if m~=n error('Matrix not sqaure') % Want square matrix for simplicityend
% Find the band of A
for l = 1:n
if A(m,l)~=0
s = n-l;
break;
end
end
% Do the sparse LU decomposition for a matrix of band sfor j = 1:m
if j >= m-s
L(j:m,j) = A(j:m,j)./A(j,j); U(j,j:m) = A(j,j:m); A(j:m,j:m) = A(j:m,j:m) - L(j:m,j)*U(j,j:m);
else L(j:j+s,j) = A(j:j+s,j)./A(j,j); U(j,j:j+s) = A(j,j:j+s); A(j:j+s,j:j+s) = A(j:j+s,j:j+s) - L(j:j+s,j)*U(j,j:j+s);
endend
L = sparse(L);
U = sparse(U);
% Call backsolve routine, which I wrote to pay heed to sparsity.[y] = Back_Solve(L,b);
[x] = Back_Solve(U,y);%
% Written by M. Harper Langston - 5/10/00
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -