チェビシェフ級数形式の多項式の導関数

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

ホーム > 製品 > nAG数値計算ライブラリ > サンプルソースコード集 > チェビシェフ級数形式の多項式の導関数 (C言語/C++)

Keyword: チェビシェフ級数, 多項式, 導関数

概要

本サンプルはチェビシェフ級数形式の多項式の導関数を求めるC言語によるサンプルプログラムです。 本サンプルは区間[-0.5, 2.5]に渡るデータをフィットする多項式の導関数を求めて出力します。

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

出力結果

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

この出力例をダウンロード
nag_1d_cheb_deriv (e02ahc) Example Program Results

   i  Argument    1st deriv    2nd deriv
   1  -0.5000       0.2453       0.1637    
   2   0.5000       0.4777       0.3185    
   3   1.5000       0.9304       0.6203    
   4   2.5000       1.8119       1.2056    

  • 3~7行目に引数、1階導関数、2階導関数が出力されています。

ソースコード

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

※本サンプルソースコードは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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

このソースコードをダウンロード
/* nag_1d_cheb_deriv (e02ahc) Example Program.
 *
 * CLL6I261D/CLL6I261DL Version.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.1, 2017.
 */

#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nage02.h>

int main(void)
{
  /* Initialized data */
  const double xmin = -0.5;
  const double xmax = 2.5;
  const double a[7] =
         { 2.53213, 1.13032, 0.2715, 0.04434, 0.00547, 5.4e-4, 4e-5 };

  /* Scalars */
  double deriv, deriv2, patm1, x;
  Integer exit_status, i, m, n, one;
  NagError fail;

  /* Arrays */
  double *adif = 0, *adif2 = 0;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_1d_cheb_deriv (e02ahc) Example Program Results\n");

  n = 6;
  one = 1;

  /* Allocate memory */
  if (!(adif = nAG_ALLOC(n + 1, double)) ||
      !(adif2 = nAG_ALLOC(n + 1, double)))
  {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* nag_1d_cheb_deriv (e02ahc).
   * Derivative of fitted polynomial in Chebyshev series form
   */
  nag_1d_cheb_deriv(n, xmin, xmax, a, one, &patm1, adif, one, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_1d_cheb_deriv (e02ahc) call 1.\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* nag_1d_cheb_deriv (e02ahc), see above. */
  nag_1d_cheb_deriv(n, xmin, xmax, adif, one, &patm1, adif2, one, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_1d_cheb_deriv (e02ahc) call 2.\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  m = 4;
  printf("\n");
  printf("   i  Argument    1st deriv    2nd deriv\n");

  for (i = 1; i <= m; ++i) {
    x = (xmin * (double) (m - i) + xmax * (double) (i - 1)) / (double) (m -
                                                                        1);
    /* nag_1d_cheb_eval2 (e02akc).
     * Evaluation of fitted polynomial in one variable from
     * Chebyshev series form
     */
    nag_1d_cheb_eval2(n, xmin, xmax, adif, one, x, &deriv, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_1d_cheb_eval2 (e02akc) call 1.\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    /* nag_1d_cheb_eval2 (e02akc), see above. */
    nag_1d_cheb_eval2(n, xmin, xmax, adif2, one, x, &deriv2, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_1d_cheb_eval2 (e02akc) call 2.\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%4ld%9.4f    %9.4f    %9.4f    \n", i, x, deriv,
           deriv2);
  }

END:
  nAG_FREE(adif);
  nAG_FREE(adif2);

  return exit_status;
}


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