Facebook
From Sharp Baboon, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 62
  1. c=randi(10,3);
  2. b=[2; 5; 4];
  3. %c=[2 1 3; 4 5 -7; -1 2 2]; SPRAWDZENIE
  4. %b=[4 ;7; -3]; SPRAWDZENIE
  5. AA=gaussian(c,b);
  6. z=length(b)+1;
  7.  
  8. bb=AA(:,z);
  9. xxx=backward(AA,bb);
  10. function Ag = gaussian(A,b)
  11. Ag = [A b];
  12. n = size(Ag,1);
  13. for k=1:n-1
  14. for i = k+1:n
  15. l = Ag(i,k) / Ag(k,k);
  16. for j = k:n+1
  17. Ag(i,j) = Ag(i,j) - l * Ag(k,j);
  18. end
  19. end
  20. end
  21. end
  22.  
  23. function x = backward(U,c)
  24. n = size(U-1,1);
  25. x = zeros(n,1);
  26. for i = n:-1:1
  27. s = 0;
  28. for j = i+1:n
  29. s = s + U(i,j)*x(j);
  30. end
  31. x(i) = (c(i) - s) / U(i,i);
  32. end
  33. end
  34.