Keyword: 多ガンマ関数, ポリガンマ関数, 実数
概要
本サンプルは実数xの多ガンマ関数(プサイ関数の導関数)を求めるC言語によるサンプルプログラムです。 本サンプルは引数xを読み込み、xの各値について以下に示される多ガンマ関数を求めて出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_real_polygamma() のExampleコードです。本サンプル及び関数の詳細情報は nag_real_polygamma のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_real_polygamma のマニュアルページを参照)1 2 3 4 5 6 7 8
このデータをダウンロード |
nag_real_polygamma (s14aec) Example Program Data 1.0 0 0.5 1 -3.6 2 8.0 3 2.9 4 -4.7 5 -5.4 6 : Values of x and k
- 1行目はタイトル行で読み飛ばされます。
- 2~8行目に引数xの値と導関数の階数(k)を指定しています。
出力結果
(本関数の詳細はnag_real_polygamma のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10
この出力例をダウンロード |
nag_real_polygamma (s14aec) Example Program Results x k (d^k/dx^k)psi(x) 1.0 0 -5.7722e-01 0.5 1 4.9348e+00 -3.6 2 -2.2335e+01 8.0 3 4.6992e-03 2.9 4 -1.5897e-01 -4.7 5 1.6566e+05 -5.4 6 4.1378e+05
- 3~10行目に引数xの値、導関数の階数、多ガンマ関数の値が出力されています。
ソースコード
(本関数の詳細はnag_real_polygamma のマニュアルページを参照)
※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
このソースコードをダウンロード |
/* nag_real_polygamma (s14aec) Example Program. * * CLL6I261D/CLL6I261DL Version. * * Copyright 2017 Numerical Algorithms Group. * * nAG C Library * * Mark 26.1, 2017. */ #include <stdio.h> #include <nag.h> #include <nag_stdlib.h> #include <nags.h> int main(void) { Integer exit_status = 0, k; NagError fail; double x, y; INIT_FAIL(fail); /* Skip heading in data file */ scanf("%*[^\n]"); printf("nag_real_polygamma (s14aec) Example Program Results\n\n"); printf(" x k (d^k/dx^k)psi(x)\n"); while (scanf("%lf %ld%*[^\n]", &x, &k) != EOF) { /* nag_real_polygamma (s14aec). * Derivative of the psi function psi(x) */ y = nag_real_polygamma(x, k, &fail); if (fail.code == NE_NOERROR) printf("%5.1f %5ld %13.4e\n", x, k, y); else { printf("Error from nag_real_polygamma (s14aec).\n%s\n", fail.message); exit_status = 1; goto END; } } END: return exit_status; }