SHARE
TWEET

jordan

a guest Jul 20th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. B = [2 8 -1;5 -1 1;-1 1 4];
  2. A = [11;10;3];
  3. E = [B A];
  4. n =length(B);
  5. for i = 1 : n-1
  6.     [m,id]=max(abs(E(i:end,i)))
  7.     id=id+i-1;
  8.     if(id~=i)
  9.          temp=E(i,:);
  10.         E(i,:)=E(id,:);
  11.         E(id,:)=temp;
  12.     end
  13.     for j = i+1 :  n
  14.         E(j,:)=E(j,:)-(E(i,:)*E(j,i))/E(i,i)
  15.     end
  16. end
  17.  
  18. % x = zeros(1,n);
  19. % for i = n:-1:1
  20. %     x(i) = (E(i,end) - (sum(E(i,1:end-1).*x)))/E(i,i);
  21. % end
  22.  
  23. for i = n:-1:2
  24.     [m,id]=max(abs(E(i:end,i)))
  25.     id=id+i-1;
  26.     if(id~=i)
  27.          temp=E(i,:);
  28.         E(i,:)=E(id,:);
  29.         E(id,:)=temp;
  30.     end
  31.     for j = i-1:-1:1
  32.         E(j,:)=E(j,:)-(E(i,:)*E(j,i))/E(i,i);
  33.     end
  34. end
  35. for i =  1 : n
  36.     E(i,:)=E(i,:)/E(i,i)
  37. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top