Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.95 KB | None | 0 0
  1. function [ wynik ]=Gauss ( M )
  2.     [n k]=size(M);
  3.     wyni=0;
  4.    
  5.     for i=1:n
  6.         if M(i,i)==0 then
  7.             j=i+1;
  8.             while j<=n & M(i,i)==0
  9.                 if M(j,i)<>0 then
  10.                     wyni=wyni+1;
  11.                     wynik(wyni,:)=[0 i j];
  12.                     tmp=M(i,:);
  13.                     M(i,:)=M(j,:);
  14.                     M(j,:)=tmp;
  15.                 end
  16.                 j=j+1;
  17.             end
  18.         end
  19.        
  20.         if M(i,i)<>1 then
  21.             wyni=wyni+1;
  22.             wynik(wyni,:)=[1 i 1/M(i,i)]
  23.             M(i,:)=M(i,:)*(1/M(i,i))
  24.         end
  25.        
  26.         for j=i+1:n
  27.             if M(j,i)<>0 then
  28.                 wyni=wyni+1;
  29.                 wynik(wyni,:)=[1 j -1/M(j,i)]
  30.                 M(j,:)=M(j,:)*(-1/M(j,i))
  31.                
  32.                 wyni=wyni+1;
  33.                 wynik(wyni,:)=[2 j i]
  34.                 M(j,:)=M(j,:)+M(i,:)
  35.             end
  36.         end
  37.     end
  38. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement