プサイ関数と対数関数との差分(Ψ(x)−ln x)

C言語によるサンプルソースコード : 使用関数名:nag_polygamma_fun (s14acc)

ホーム > 製品 > nAG数値計算ライブラリ > サンプルソースコード集 > プサイ関数と対数関数との差分(Ψ(x)−ln x) (C言語/C++)

Keyword: プサイ関数, 対数関数

概要

本サンプルはプサイ関数と対数関数との差分(Ψ(x)−ln x)を求めるC言語によるサンプルプログラムです。 本サンプルは引数xを読み込み、xの各値についてΨ(x)−ln xを求めて出力します。この場合Ψは以下で表わされます。

プサイ関数と対数関数との差分のデータ 

※本サンプルはnAG Cライブラリに含まれる関数 nag_polygamma_fun() のExampleコードです。本サンプル及び関数の詳細情報は nag_polygamma_fun のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで

入力データ

(本関数の詳細はnag_polygamma_fun のマニュアルページを参照)
1
2
3
4
5

このデータをダウンロード
nag_polygamma_fun (s14acc) Example Program Data
0.1
0.5
3.6
8.0

  • 1行目はタイトル行で読み飛ばされます。
  • 2~5行目に引数xの値を指定しています。

出力結果

(本関数の詳細はnag_polygamma_fun のマニュアルページを参照)
1
2
3
4
5
6

この出力例をダウンロード
nag_polygamma_fun (s14acc) Example Program Results
     x       psi(x)-log(x)
   0.100        -8.1212
   0.500        -1.2704
   3.600        -0.1453
   8.000        -0.0638

  • 3~6行目に引数xの値とΨ(x)−ln xの値が出力されています。

ソースコード

(本関数の詳細はnag_polygamma_fun のマニュアルページを参照)

※本サンプルソースコードは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

このソースコードをダウンロード
/* nag_polygamma_fun (s14acc) 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 f, x;
  NagError fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_polygamma_fun (s14acc) Example Program Results\n");
  printf("     x       psi(x)-log(x)\n");
  while (scanf("%lf", &x) != EOF)
  {
    /* nag_polygamma_fun (s14acc).
     * psi(x) - ln(x)
     */
    f = nag_polygamma_fun(x, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_polygamma_fun (s14acc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%8.3f %14.4f\n", x, f);
  }

END:
  return exit_status;
}


関連情報
© 日本ニューメリカルアルゴリズムズグループ株式会社 2025
Privacy Policy  /  Trademarks