Advertisement
CapsLock007

gauss

May 12th, 2022
1,698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.56 KB | None | 0 0
  1. function X = gauss(A,b)
  2. E=[A b]
  3. n=size(A,1);
  4.   for i=1:1:n-1
  5.     E(i,:) = E(i,:) + E(i+1,:);
  6.   end
  7. E(n,1)=E(n,1)+E(1,1);
  8. q=1;
  9.   for i=q:1:n
  10.     for j=1:1:n
  11.       if E(j,i)==0;
  12.           E(j,:)=E(j,:);
  13.       else
  14.         E(j,:)=E(j,:)/E(j,i);
  15.     end
  16.   end
  17.  
  18.   for k=i+1:1:n
  19.     E(k,:)=E(k,:)-E(i,:);
  20.   end
  21. q=i+1;
  22.       end
  23. q=n;
  24.   for i=n:-1:1
  25.     for j=1:1:q
  26.       if E(j,i)==0;
  27.         E(j,:)=E(j,:);
  28.       else
  29.         E(j,:)=E(j,:)/E(j,i);
  30.     end
  31.   end
  32.  
  33.   for k=1:1:i-1
  34.     E(k,:)=E(k,:)-E(i,:);
  35.   end
  36. q=q-1;
  37.       end
  38. X=E(:,n+1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement