How fix this GaussPivot code, since I got a nonsense results for this specific a, b matrix?

5 views (last 30 days)
unction x = GaussPivot(a,b)
format long
% The function solves a system of linear equations ax = b using the Gauss
% eliminaion mehod with pivoting
ab = [a,b];
[R, c] = size(ab);
for j = 1:R-1
% Pivoting block
if ab(j,j) == 0
for k = j +1:R
if ab(k,j) ~=0
abTemp = ab(j,:);
ab(j, :) = ab(k,:);
ab (k,:) = abTemp;
break
end
end
end
% Pivoting block ends
for i = j+1:R
ab(i,j:c) = ab(i,j:c)-ab(i,j)/ab(j,j)*ab(j,j:c);
end
end
x = zeros(R,1);
x(R)= ab(R,c)/ab(R,R);
for i= R-1:-1:1
x(i) = (ab(i,c) -ab(i,i +1:R)*x(i+1:R))/ab(i,i);
end
and a and b matrix
a = [0 0.9231 0 0 0 0 0 0; -1 -0.3846 0 0 0 0 0 0; 0 0 0 0 1 0 0.8575 0;
1 0 -0.7809 0 0 0 0 0; 0 -0.3846 -0.7809 0 -1 0.3846 0 0;
0 0.9231 0.6247 0 0 -0.9231 0 0; 0 0.6247 -1 0 0 0 0 0;
0 0 0 1 0 0 -0.5145 -1];
b = [1690;3625;0;0;0;0;0;0];
Forces = GaussPivot(a,b)

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!