std:: beta, std:: betaf, std:: betal
|
double
beta
(
double
x,
double
y
)
;
float
betaf
(
float
x,
float
y
)
;
|
(1) | |
|
Promoted beta
(
Arithmetic x, Arithmetic y
)
;
|
(2) | |
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 ∫ 10 t x-1
(1 - t) (y-1)
d t , or, equivalently,
| Γ(x)Γ(y) |
| Γ(x + y) |
错误处理
错误报告方式可按照 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)! |
⎜
⎝ 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 网络资源。