Advertisement
noctual

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

Jul 5th, 2021
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.42 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.   Q: array [0..n, 0..n] of real;
  9.    
  10. begin
  11.   mas[0, 0] := 0; mas[0, 1] := -1; mas[0, 2] := 1;
  12.   mas[1, 0] := 4; mas[1, 1] := 2; mas[1, 2] := 0;
  13.   mas[2, 0] := 3; mas[2, 1] := 4; mas[2, 2] := 0;
  14.  
  15.   Q[0, 0] := 1; Q[0, 1] := 0; Q[0, 2] := 0;
  16.   Q[1, 0] := 0; Q[1, 1] := 1; Q[1, 2] := 0;
  17.   Q[2, 0] := 0; Q[2, 1] := 0; Q[2, 2] := 1;
  18.  
  19.   for col := 0 to n do
  20.   begin
  21.    for row := col+1 to n do
  22.     if mas[row, col] <> 0 then
  23.     begin
  24.       r := sqrt(mas[col, col]*mas[col, col] + mas[row, col]*mas[row, col]);
  25.       c := mas[col, col] / r;
  26.       s := -mas[row, col] / r;
  27.      
  28.       for i := 0 to n do
  29.       begin
  30.         {R}
  31.         col_i := mas[col, i] * c + mas[row, i] * (-s);
  32.         row_i := mas[col, i] * s + mas[row, i] * c;
  33.         mas[col, i] := col_i;
  34.         mas[row, i] := row_i;
  35.         {Q}
  36.         col_i := Q[i, col] * c + Q[i, row] * (-s);
  37.         row_i := Q[i, col] * s + Q[i, row] * c;
  38.         Q[i, col] := col_i;
  39.         Q[i, row] := row_i;
  40.       end;
  41.     end;
  42.   end;
  43.  
  44.   writeln('R:');
  45.   for i := 0 to n do
  46.   begin
  47.    for j := 0 to n do
  48.     write(round(mas[i, j] * eps) / eps, Chr(9));
  49.   writeln();
  50.   end;
  51.  
  52.   writeln('Q:');
  53.   for i := 0 to n do
  54.   begin
  55.    for j := 0 to n do
  56.     write(round(Q[i, j] * eps) / eps, Chr(9));
  57.   writeln();
  58.   end;
  59. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement