Advertisement
noctual

Givens rotation / Поворот Гивенса

Jul 5th, 2021
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.92 KB | None | 0 0
  1. const
  2.   n = 2;
  3.   eps = 1000;
  4. var
  5.   col, row, i, j: integer;
  6.   r,c,s, row_i, col_i: real;
  7.   mas: array [0..n, 0..n] of real;
  8.    
  9. begin
  10.   mas[0, 0] := 0; mas[0, 1] := -1; mas[0, 2] := 1;
  11.   mas[1, 0] := 4; mas[1, 1] := 2; mas[1, 2] := 0;
  12.   mas[2, 0] := 3; mas[2, 1] := 4; mas[2, 2] := 0;
  13.  
  14.   for col := 0 to n do
  15.   begin
  16.    for row := col+1 to n do
  17.     if mas[row, col] <> 0 then
  18.     begin
  19.       r := sqrt(mas[col, col]*mas[col, col] + mas[row, col]*mas[row, col]);
  20.       c := mas[col, col] / r;
  21.       s := -mas[row, col] / r;
  22.      
  23.       for i := 0 to n do
  24.       begin
  25.         col_i := mas[col, i] * c + mas[row, i] * (-s);
  26.         row_i := mas[col, i] * s + mas[row, i] * c;
  27.         mas[col, i] := col_i;
  28.         mas[row, i] := row_i;
  29.       end;
  30.     end;
  31.   end;
  32.  
  33.   writeln('R:');
  34.   for i := 0 to n do
  35.   begin
  36.    for j := 0 to n do
  37.     write(round(mas[i, j] * eps) / eps, Chr(9));
  38.   writeln();
  39.   end;
  40. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement