Keyword: 双3次, スプライン
概要
本サンプルは双3次スプラインの評価を行うC言語によるサンプルプログラムです。 本サンプルは以下に示されるデータについて双3次スプラインの値を求めて出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_2d_spline_eval() のExampleコードです。本サンプル及び関数の詳細情報は nag_2d_spline_eval のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_2d_spline_eval のマニュアルページを参照)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
このデータをダウンロード |
nag_2d_spline_eval (e02dec) Example Program Data 7 11 10 1.0 1.0 1.0 1.0 1.3 1.5 1.6 2.0 2.0 2.0 2.0 0.0 0.0 0.0 0.0 0.4 0.7 1.0 1.0 1.0 1.0 1.0000 1.1333 1.3667 1.7000 1.9000 2.0000 1.2000 1.3333 1.5667 1.9000 2.1000 2.2000 1.5833 1.7167 1.9500 2.2833 2.4833 2.5833 2.1433 2.2767 2.5100 2.8433 3.0433 3.1433 2.8667 3.0000 3.2333 3.5667 3.7667 3.8667 3.4667 3.6000 3.8333 4.1667 4.3667 4.4667 4.0000 4.1333 4.3667 4.7000 4.9000 5.0000 1.0 0.0 1.1 0.1 1.5 0.7 1.6 0.4 1.9 0.3 1.9 0.8 2.0 1.0
- 1行目はタイトル行で読み飛ばされます。
- 2行目にスプライン評価点の数(m)を指定しています。
- 3行目にx方向のノット数(nx)、y方向のノット数(ny)を指定しています。
- 4行目に変数xに関するノット(lamda)を指定しています。
- 5行目に変数yに関するノット(mu)を指定しています。
- 6~12行目に双3次スプライン係数(c)を指定しています。
- 13~19行目にスプラインの値が必要となる点のx座標、y座標を指定しています。
出力結果
(本関数の詳細はnag_2d_spline_eval のマニュアルページを参照)1 2 3 4 5 6 7 8 9
この出力例をダウンロード |
nag_2d_spline_eval (e02dec) Example Program Results i x[i] y[i] ff[i] 0 1.000 0.000 1.000 1 1.100 0.100 1.310 2 1.500 0.700 2.950 3 1.600 0.400 2.960 4 1.900 0.300 3.910 5 1.900 0.800 4.410 6 2.000 1.000 5.000
- 2~9行目にインデックス、xの値、yの値、スプラインの値が出力されています。
ソースコード
(本関数の詳細はnag_2d_spline_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 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
このソースコードをダウンロード |
/* nag_2d_spline_eval (e02dec) 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; NagError fail; Nag_2dSpline spline; double *ff = 0, *x = 0, *y = 0; INIT_FAIL(fail); /* Initialize spline */ spline.lamda = 0; spline.mu = 0; spline.c = 0; printf("nag_2d_spline_eval (e02dec) Example Program Results\n"); scanf("%*[^\n]"); /* Skip heading in data file */ /* Read m, the number of spline evaluation points. */ scanf("%ld", &m); if (m >= 1) { if (!(x = nAG_ALLOC(m, double)) || !(y = nAG_ALLOC(m, double)) || !(ff = nAG_ALLOC(m, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid m.\n"); exit_status = 1; return exit_status; } /* Read nx and ny, the number of knots in the x and y directions. */ scanf("%ld%ld", &(spline.nx), &(spline.ny)); if (spline.nx >= 8 && spline.ny >= 8) { if (!(spline.c = nAG_ALLOC((spline.nx - 4) * (spline.ny - 4), double)) || !(spline.lamda = nAG_ALLOC(spline.nx, double)) || !(spline.mu = nAG_ALLOC(spline.ny, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid spline.nx or spline.ny.\n"); exit_status = 1; return exit_status; } /* read the knots lamda[0] .. lamda[nx-1] and mu[0] .. mu[ny-1]. */ for (i = 0; i < spline.nx; i++) scanf("%lf", &(spline.lamda[i])); for (i = 0; i < spline.ny; i++) scanf("%lf", &(spline.mu[i])); /* Read c, the bicubic spline coefficients. */ for (i = 0; i < (spline.nx - 4) * (spline.ny - 4); scanf("%lf", &(spline.c[i])), i++); /* Read the x and y co-ordinates of the evaluation points. */ for (i = 0; i < m; i++) scanf("%lf%lf", &x[i], &y[i]); /* Evaluate the spline at the m points. */ /* nag_2d_spline_eval (e02dec). * Evaluation of bicubic spline, at a set of points */ nag_2d_spline_eval(m, x, y, ff, &spline, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_2d_spline_eval (e02dec).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print the results. */ printf(" i x[i] y[i] ff[i]\n"); for (i = 0; i < m; i++) printf("%7ld %11.3f%11.3f%11.3f\n", i, x[i], y[i], ff[i]); nAG_FREE(spline.lamda); nAG_FREE(spline.mu); nAG_FREE(spline.c); END: nAG_FREE(x); nAG_FREE(y); nAG_FREE(ff); return exit_status; }