最終更新日時(UTC):
が更新

履歴 編集

function template
<linalg>

std::linalg::setup_givens_rotation(C++26)

namespace std::linalg {
  template<class Real>
  setup_givens_rotation_result<Real>
    setup_givens_rotation(Real a, Real b) noexcept; // (1)

  template<class Real>
  setup_givens_rotation_result<complex<Real>>
    setup_givens_rotation(complex<Real> a, complex<Real> b) noexcept; // (2)
}

概要

ギブンス回転を計算する。すなわち、以下の式が成り立つような、Real型の値cs, rを計算する。

$$ \begin{split} \begin{pmatrix} c & s \\ -\overline{s} & c \end{pmatrix} \begin{pmatrix} a \\ b \end{pmatrix} &= \begin{pmatrix} r \\ 0 \end{pmatrix},\\ c^2 + |s|^2 &= 1 \end{split} $$

ただし、srの型はabの型による。

  • (1) abの型がRealの場合、srの型もRealrは$(a, b)^T$のユークリッドノルム、つまり$\sqrt{|a|^2 + |b|^2}$である。
  • (2) abの型がcomplex<Real>の場合、srの型もcomplex<Real>。以下で定義される$sgn$関数を用いると、rは$sgn(a) * \sqrt{|a|^2 + |b|^2}$である。 $$ sgn(x):= \begin{cases} \frac{x}{|x|} & \text{($x \neq 0$)} \\ 1 & \text{($x = 0$)} \end{cases} $$

適格要件

  • Realcomplex<Real>が規定できる型であること。

戻り値

csが入力$(a, b)^T$に対するギブンス回転行列の成分で、rを入力$(a, b)^T$のユークリッドノルムとすると、戻り値は{c, s, r}である。

[注意] 処理系にあるコンパイラで確認していないため、間違っているかもしれません。

#include <cmath>
#include <complex>
#include <iostream>
#include <linalg>

template <class T>
void print(const std::linalg::setup_givens_rotation_result<T>& result) {
  std::cout << "c: " << result.c << '\n'
            << "s: " << result.s << '\n'
            << "r: " << result.r << '\n';
}

int main()
{
  // (1)
  std::cout << "(1)\n";
  auto result1 = std::linalg::setup_givens_rotation(1.0, std::sqrt(3.0));
  print(result1);

  // (2)
  std::cout << "(2)\n";
  auto result2 = std::linalg::setup_givens_rotation(std::complex<double>(1.0, 0), std::complex<double>(0, std::sqrt(3.0)));
  print(result2);

  return 0;
}

出力

(1)
c: 0.5
s: -0.866025
r: 2.0
(2)
c: 0.5
s: (0,-0.866025)
r: (2,0)

バージョン

言語

  • C++26

処理系

関連項目

参照