Namespaces
Variants

std:: beta, std:: betaf, std:: betal

From cppreference.net
double beta ( double x, double y ) ;

float betaf ( float x, float y ) ;

long double betal ( long double x, long double y ) ;
(1)
Promoted    beta ( Arithmetic x, Arithmetic y ) ;
(2)
1) 计算 x y Beta 函数
2) 一组重载或函数模板,用于处理 (1) 未涵盖的所有算术类型参数组合。若任一参数具有 整数类型 ,则将其转换为 double 。若任一参数为 long double ,则返回类型 Promoted 也为 long double ,否则返回类型始终为 double

与所有特殊函数一样,只有当实现将 __STDCPP_MATH_SPEC_FUNCS__ 定义为至少 201003L 的值,且用户在包含任何标准库头文件之前定义了 __STDCPP_WANT_MATH_SPEC_FUNCS__ 时,才保证 beta 函数在 <cmath> 中可用。

目录

参数

x, y - 浮点或整型类型的值

返回值

If no errors occur, value of the beta function of x and y , that is 1
0
t x-1
(1 - t) (y-1)
d t
, or, equivalently,
Γ(x)Γ(y)
Γ(x + y)
is returned.

错误处理

错误报告方式可按照 math_errhandling 中的规定执行。

  • 若任一参数为 NaN,则返回 NaN 且不报告定义域错误。
  • 本函数仅要求在 x y 均大于零时有定义,否则允许报告定义域错误。

注释

不支持 TR 29124 但支持 TR 19768 的实现,会在头文件 tr1/cmath 和命名空间 std::tr1 中提供此函数。

此函数的实现也可在 boost.math库 中找到。

beta ( x, y ) 等于 beta ( y, x )

When x and y are positive integers, beta(x, y) equals
(x - 1)!(y - 1)!
(x + y - 1)!
. Binomial coefficients can be expressed in terms of the beta function:

n
k


=
1
(n + 1)Β(n - k + 1, k + 1)
.

示例

(在 gcc 6.0 环境下运行结果如图所示)

#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
double binom(int n, int k)
{
    return 1 / ((n + 1) * std::beta(n - k + 1, k + 1));
}
int main()
{
    std::cout << "Pascal's triangle:\n";
    for (int n = 1; n < 10; ++n)
    {
        std::cout << std::string(20 - n * 2, ' ');
        for (int k = 1; k < n; ++k)
            std::cout << std::setw(3) << binom(n, k) << ' ';
        std::cout << '\n';
    }
}

输出:

Pascal's triangle:
                  2 
                3   3 
              4   6   4 
            5  10  10   5 
          6  15  20  15   6 
        7  21  35  35  21   7 
      8  28  56  70  56  28   8 
    9  36  84 126 126  84  36   9

参见

(C++11) (C++11) (C++11)
gamma 函数
(函数)

外部链接

魏斯坦, 埃里克·W. "Beta 函数." 来自 MathWorld——一个 Wolfram 网络资源。