std::erf, std::erff, std::erfl
提供: cppreference.com
ヘッダ <cmath> で定義 | ||
float erf (float arg ); float erff(float arg ); | (1) | (C++11以上) |
double erf (double arg ); | (2) | (C++11以上) |
longdouble erf (longdouble arg ); longdouble erfl(longdouble arg ); | (3) | (C++11以上) |
double erf ( 整数型 arg ); | (4) | (C++11以上) |
目次 |
[編集]引数
arg | - | 浮動小数点または整数型の値 |
[編集]戻り値
エラーが発生しなければ、arg
の誤差関数の値、つまり 2 |
√π |
0e-t2
dt が返されます。
2*arg |
√π |
[編集]エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 ±0 が返されます。
- 引数が ±∞ であれば、 ±1 が返されます。
- 引数が NaN であれば、 NaN が返されます。
[編集]ノート
|arg|<DBL_MIN*(sqrt(π)/2) の場合、アンダーフローが保証されます。
erf(x |
σ√2 |
[編集]例
以下の例は標準変量が区間 (x1, x2) 上である確率を計算します
Run this code
#include <iostream>#include <cmath>#include <iomanip>double phi(double x1, double x2){return(std::erf(x2/std::sqrt(2))- std::erf(x1/std::sqrt(2)))/2;}int main(){std::cout<<"normal variate probabilities:\n"<<std::fixed<<std::setprecision(2);for(int n=-4; n<4;++n)std::cout<<"["<<std::setw(2)<< n <<":"<<std::setw(2)<< n+1<<"]: "<<std::setw(5)<<100*phi(n, n+1)<<"%\n"; std::cout<<"special values:\n"<<"erf(-0) = "<< std::erf(-0.0)<<'\n'<<"erf(Inf) = "<< std::erf(INFINITY)<<'\n';}
出力:
normal variate probabilities: [-4:-3]: 0.13% [-3:-2]: 2.14% [-2:-1]: 13.59% [-1: 0]: 34.13% [ 0: 1]: 34.13% [ 1: 2]: 13.59% [ 2: 3]: 2.14% [ 3: 4]: 0.13% special values: erf(-0) = -0.00 erf(Inf) = 1.00
[編集]関連項目
(C++11)(C++11)(C++11) | 相補誤差関数を計算します (関数) |
erf の C言語リファレンス |
[編集]外部リンク
Weisstein, Eric W. "Erf." From MathWorld--A Wolfram Web Resource.