Keyword: ガンマ関数
概要
本サンプルはガンマ関数を求めるC言語によるサンプルプログラムです。 本サンプルは引数xを読み込み、xの各値について以下に示されるガンマ関数を求めて出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_gamma() のExampleコードです。本サンプル及び関数の詳細情報は nag_gamma のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_gamma のマニュアルページを参照)- 1行目はタイトル行で読み飛ばされます。
- 2〜9行目にガンマ関数の引数xの値を指定しています。
出力結果
(本関数の詳細はnag_gamma のマニュアルページを参照)| この出力例をダウンロード |
nag_gamma (s14aac) Example Program Results
x y
1.000e+00 1.000e+00
1.250e+00 9.064e-01
1.500e+00 8.862e-01
1.750e+00 9.191e-01
2.000e+00 1.000e+00
5.000e+00 2.400e+01
1.000e+01 3.629e+05
-1.500e+00 2.363e+00
- 3〜10行目に引数xの値とガンマ関数の値が出力されています。
ソースコード
(本関数の詳細はnag_gamma のマニュアルページを参照)
※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
/* nag_gamma (s14aac) 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_gamma (s14aac) Example Program Results\n");
printf(" x y\n");
while (scanf("%lf", &x) != EOF)
{
/* nag_gamma (s14aac).
* Gamma function Gamma(x)
*/
y = nag_gamma(x, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_gamma (s14aac).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
printf("%12.3e%12.3e\n", x, y);
}
END:
return exit_status;
}
