Advertisement
MLCPRO

zeydel

Jan 29th, 2022
971
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %Исходные данные
  2. A = [1,-0.08,0.23,-0.32;
  3.     -0.16,1.23,-0.18,-0.16;
  4.     -0.15,-0.12,0.68,0.18;
  5.     -0.25,-0.21,0.16,0.97;];
  6.  
  7. B = [1.34,-2.33,0.34,0.63];
  8.  
  9.  
  10. %размер системы
  11. N = max(size(B));
  12.  
  13. %требуемая точность
  14. e = 0.0001;
  15.  
  16.  
  17. X= [zeros(1,N);
  18.     zeros(1,N)];
  19.  
  20. root = zeros(1,N);
  21. %Начальные приближения
  22. for i = 1:N
  23.     root(i) = B(1,i) / A(i,i);
  24. end
  25.  
  26. m = max(abs(root));
  27.  
  28. %Итерации
  29.  
  30. while m>e
  31.     for i = 1:N
  32.         X (1,i) = root(i);
  33.         ss = B(1,i);
  34.         for j = 1:N
  35.             if(i ~= j)
  36.                 ss = ss - A(i,j)*root(j);
  37.             end;
  38.         end;
  39.         root(i) = ss/A(i,i);
  40.         X(2,i) = root(i) - X(1,i);
  41.     end;
  42.     m = max(abs(X(2)));
  43. end;
  44.  
  45. disp (root)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement