Facebook
From Voluminous Tortoise, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 232
  1. g=[5 -6 4 3; 3 -3 2 2; 4 -5 2 1];
  2. wektor=g;
  3. n=3;
  4. for i=1:(n-1)
  5.     for j=(i+1):n
  6.         mn=g(j,i)/g(i,i);
  7.         for k=i:(n+1)
  8.             g(j,k)=g(j,k)-(g(i,k)*mn);
  9.         end
  10.     end
  11. end
  12. a
  13. x(1,n)=g(n,n+1)/g(n,n);
  14.  
  15. for i=(n-1):-1:1
  16.     suma=0;
  17.     for j=(i+1):n
  18.         suma=suma+(g(i,j)*x(1,j));
  19.     end
  20.     x(i)=(1/g(i,i))*(g(i,n+1)-suma);
  21. end
  22. x  %%Wektor rozwiązań
  23. wektor(:,1:3/wektor(:,4))   %% Macierz po eleminacji