Combining Functions of Gaussian elimination and Banded Matrix

3 次查看(过去 30 天)
Goal: to create a banded version of Gaussian elimination without pivoting.
%%Work so far: I have a code that generates a banded matrix. . .
function [Z]=bandmatrix(n,k1,k2)
Z=zeros(n,n);
for i=1:n
for j=1:n
Z(i,j)=1;
end
end
for i=1:n
for j=1:n
if (j<i-k1) Z(i,j)=0;
end
if(j>i+k2) Z(i,j)=0;
end
end
end
%% I have a code for GE without pivoting as. . .
function [x] = GE_WithoutPivoting1(A,b)
n = length(b);
for k=1:n-1
if abs(A(k,k)) < 1e-15
error('A has diagonal entries of zero')
end
for i=k+1:n
m = -A(i,k)/A(k,k); % multiplier for current row i
for j=k+1:n
A(i,j) = A(i,j) + m*A(k,j);
end
b(i) = b(i) + m*b(k);
end
end
x = GE_BackSubstitution(A,b);
QUESTION: to achieve my goal as in above, i.e., to properly implement a banded version of Gaussian elimination without pivoting. What I did was to call the GE elimination at end of the function [Z]=bandmatrix(n,k1,k2) i.e.,
function [Z]=bandmatrix(n,k1,k2)
....
....
x = GE_BackSubstitution(A,b); %This is already in my working directory
But my fear is that function [Z]=bandmatrix(n,k1,k2) might not be working and that it is function [x] = GE_WithoutPivoting1(A,b) that is working (since it is already saved on my working directory).
Please, using my two functions how do I implement a banded version of GE without pivoting. Any edition to my written codes will be welcome. Thank you

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by