Keyword: 対数ガンマ関数
概要
本サンプルは対数ガンマ関数を求めるC言語によるサンプルプログラムです。 本サンプルは引数xを読み込み、xの各値について以下に示される対数ガンマ関数を求めて出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_log_gamma() のExampleコードです。本サンプル及び関数の詳細情報は nag_log_gamma のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_log_gamma のマニュアルページを参照)- 1行目はタイトル行で読み飛ばされます。
- 2〜10行目に対数ガンマ関数の引数xの値を指定しています。
出力結果
(本関数の詳細はnag_log_gamma のマニュアルページを参照)| この出力例をダウンロード |
nag_log_gamma (s14abc) Example Program Results
x y
1.000e+00 0.000e+00
1.250e+00 -9.827e-02
1.500e+00 -1.208e-01
1.750e+00 -8.440e-02
2.000e+00 0.000e+00
5.000e+00 3.178e+00
1.000e+01 1.280e+01
2.000e+01 3.934e+01
1.000e+03 5.905e+03
- 3〜11行目に引数xの値と対数ガンマ関数の値が出力されています。
ソースコード
(本関数の詳細はnag_log_gamma のマニュアルページを参照)
※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
/* nag_log_gamma (s14abc) Example Program.
*
* CLL6I261D/CLL6I261DL Version.
*
* Copyright 2017 Numerical Algorithms Group.
*
* Mark 26.1, 2017.
*/
#include <nag.h>
#include <stdio.h>
#include <nag_stdlib.h>
#include <nags.h>
int main(void)
{
Integer exit_status = 0;
double x, y;
NagError fail;
INIT_FAIL(fail);
/* Skip heading in data file */
scanf("%*[^\n]");
printf("nag_log_gamma (s14abc) Example Program Results\n");
printf(" x y\n");
while (scanf("%lf", &x) != EOF)
{
/* nag_log_gamma (s14abc).
* Log Gamma function ln(Gamma(x))
*/
y = nag_log_gamma(x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_log_gamma (s14abc).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
printf("%12.3e%12.3e\n", x, y);
}
END:
return exit_status;
}
