Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- close all;
- X=[1,1,1,0;2,2,1,-1;0,3,1,2;1,2,2,1];
- Y=[4;6;-1;4];
- Z=[X,Y];
- while ismember(0,diag(X))
- for i=1:size(X,1)
- if X(i,i)==0
- for j=1:size(X,1)
- if X(j,j)~=0
- Z([i,j],:)=Z([j,i],:);
- X([i,j],:)=X([j,i],:);
- end;
- end;
- end;
- end;
- end;
- for i=1:size(Z,1)
- if Z(i,i)==0
- Z(i,:)=Z(i,:)+Z(i+1,:);
- end;
- Z(i,:)=Z(i,:)./Z(i,i);
- for j=1:size(Z,1)
- if i ~= j
- Z(j,:)=Z(j,:)-(Z(i,:).* Z(j,i));
- end;
- end;
- end;
- Z
- wynik=Z(:,size(Z,2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement