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

履歴 編集

function
<cmath>

std::beta

namespace std {
  double
    beta(double x,
         double y);              // (1) C++17
  floating-point-type
    beta(floating-point-type x,
         floating-point-type y); // (1) C++23

  Promoted
    beta(Arithmetic1 x,
         Arithmetic2 y);         // (2) C++17

  float
    betaf(float x,
          float y);              // (3) C++17

  long double
    betal(long double x,
          long double y);        // (4) C++17
}

概要

ベータ関数 (beta function) を求める。

戻り値

引数 x, y のベータ関数 B(x,y)=01dt tx1(1t)y1=Γ(x)Γ(y)Γ(x+y)for x>0,y>0 を返す。Γ はガンマ関数 (tgamma)。

備考

#include <cmath>
#include <iostream>

int main() {
  std::cout << "beta(0, 0)      = " << std::beta(0, 0) << std::endl;      // 定義域エラー; 特異点
  std::cout << "beta(-0.5, 1.5) = " << std::beta(-0.5, 1.5) << std::endl; // 定義域エラー; 解析接続すれば -π
  std::cout << "beta(1, 1)      = " << std::beta(1, 1) << std::endl;      // 1
  std::cout << "beta(2, 4)      = " << std::beta(2, 4) << std::endl;      // 1 / 20
}

出力例

beta(0, 0)      = -nan
beta(-0.5, 1.5) = 3.14159
beta(1, 1)      = 1
beta(2, 4)      = 0.05

バージョン

言語

  • C++17

処理系

備考

GCC (libstdc++)

GCC 7.1.0–8.0.0 では betaexplgamma を用いて |B(x,y)|=exp(ln|Γ(x)Γ(y)/Γ(x+y)|)) を計算する。 x < 0 || y < 0 でも定義域エラーを報告せずに値を返すが、戻り値は必ず正になる。

参照