Advertisement
elektryk798

MN_lab3_gauss

Apr 20th, 2017
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.46 KB | None | 0 0
  1. A=[3,1,-1;-1,5,-1;2,4,8]
  2. b=[6;10;2]
  3. wynik=A\b
  4. [x,Ur] = f_gauss(A,b)
  5.  
  6.  
  7. function [x,Ur]=f_gauss(A,b)
  8. [n,m]=size(A);
  9. x = zeros(n,1);
  10. if (n~=m) error('Macierz A musi byc kwadratowa'); end
  11.     Ur = [A,b];
  12.   for k=1:(n-1)
  13.   if A(k,k)==0
  14.   error;
  15.   end
  16.   for jj=k+1:(n+1)
  17.   for ii=k+1:n
  18.  Ur(ii,jj)=Ur(ii,jj)-Ur(ii,k)*Ur(k,jj)/Ur(k,k);
  19. end
  20. end
  21. end
  22. %x=0;
  23. for ii=n:-1:1
  24. S=0;
  25. for jj=ii+1:n
  26. S=S+Ur(ii,jj)*x(jj);
  27. end
  28. x(ii)=(Ur(ii,n+1)-S)/Ur(ii,ii)
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement