I try to solve system of lineare equation using the Gauss Jordan methode. I try my code with a smaller matrice and I got the rigth answer. Now I try it with a bigger matrice and I got NAN(not a number) as answer. I don't what I am doing wrong.
a = [-1 0 0 0 0 0 1 0 0 0 1 0 0 0;
0 -1 0 0 0 0 0 1 0 0 0 1 0 0 ;
1 0 -1 0 -1 0 0 0 0 0 0 0 0 0;
0 1 0 -1 0 -1 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0 -1 0 -1 0;
0 0 0 0 0 1 0 0 0 0 0 -1 0 -1;
0 0 1 0 0 0 -1 0 -1 0 0 0 0 0;
0 0 0 1 0 0 0 -1 0 -1 0 0 0 0;
-0.025 0 1 0 0 0 0 0 0 0 0 0 0 0;
0 -0.8 0 1 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 -0.04 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 -0.96 0 0 0 0 0 1 0 0;
0 0 -0.04 0 0 0 0 0 1 0 0 0 0 0;
0 0 0 -0.96 0 0 0 0 0 1 0 0 0 0];
b = [-50;-50;0;0;0;0;0;0;0;0;0;0;0;0];
Gaussjordan(a,b);
% Function Gauss Jordan
function x=Gaussjordan(a,b)
ab=[a b];
[m,n]=size(ab); %size of matrix
for i=1:m
ab(i,:)=ab(i,:)/ab(i,i);
for j=1:m
if j==i; continue;
end
ab(j,:)=ab(j,:)-ab(j,i)*ab(i,:);
end;
end;
x=ab(:,length(b)+1);
end
with the samll matrix a = [1 1 1; 2 -3 4; 3 4 5] b = [9; 13; 40], I got the answer ans = [1 3 5].
But with the bigger one upon in code I got ans = [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]
Did someone has an idea? Ps: I solve this systen of equation with fsolve to be sure that it exist an answer on the system equation