チェビシェフ級数形式の多項式の評価

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

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

Keyword: チェビシェフ級数, 多項式, 評価

概要

本サンプルはチェビシェフ級数形式の多項式を求めるC言語によるサンプルプログラムです。 本サンプルは区間−1≤ x ≤1 の等間隔のデータ点で4次多項式を計算し出力します。

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

入力データ

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

このデータをダウンロード
nag_1d_cheb_eval (e02aec) Example Program Data
  11
   4
     2.0000
     0.5000
     0.2500
     0.1250
     0.0625

  • 1行目はタイトル行で読み飛ばされます。
  • 2行目に等間隔のデータ点の数(m)を指定しています。
  • 3行目に多項式の次数(n)を指定しています。
  • 4~8行目にチェビシェフ係数(a)を指定しています。

出力結果

(本関数の詳細はnag_1d_cheb_eval のマニュアルページを参照)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

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

   R       Argument       Value of polynomial 
   1       -1.0000            0.6875
   2       -0.8000            0.6613
   3       -0.6000            0.6943
   4       -0.4000            0.7433
   5       -0.2000            0.7843
   6        0.0000            0.8125
   7        0.2000            0.8423
   8        0.4000            0.9073
   9        0.6000            1.0603
  10        0.8000            1.3733
  11        1.0000            1.9375

  • 3~14行目にインデックス、引数、多項式の値が出力されています。

ソースコード

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

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

このソースコードをダウンロード
/* nag_1d_cheb_eval (e02aec) 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 <nage02.h>

int main(void)
{
  Integer exit_status = 0, i, m, n, r;
  NagError fail;
  double *a = 0, p, xcap;

  INIT_FAIL(fail);

  printf("nag_1d_cheb_eval (e02aec) Example Program Results \n");

  /* Skip heading in data file */
  scanf("%*[^\n]");
  while ((scanf("%ld", &m) != EOF))
  {
    if (m > 0) {
      scanf("%ld", &n);
      if (n >= 0) {
        if (!(a = nAG_ALLOC(n + 1, double)))
        {
          printf("Allocation failure\n");
          exit_status = -1;
          goto END;
        }
      }
      else {
        printf("Invalid n.\n");
        exit_status = 1;
        return exit_status;
      }
      for (i = 0; i < n + 1; ++i)
        scanf("%lf", &a[i]);
      printf("\n   R       Argument       Value of polynomial \n");
      for (r = 1; r <= m; ++r) {
        xcap = (double) (2 * r - m - 1) / (double) (m - 1);
        /* nag_1d_cheb_eval (e02aec).
         * Evaluates the coefficients of a Chebyshev series
         * polynomial
         */
        nag_1d_cheb_eval(n + 1, a, xcap, &p, &fail);
        if (fail.code != NE_NOERROR) {
          printf("Error from nag_1d_cheb_eval (e02aec).\n%s\n", fail.message);
          exit_status = 1;
          goto END;
        }
        printf(" %3ld%14.4f    %14.4f\n", r, xcap, p);
      }
    }
  END:
    nAG_FREE(a);
  }
  return exit_status;
}


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