Keyword: 修正シェパード, Shepard, 二次補間
概要
本サンプルは修正シェパード(Shepard)法を用いた二次補間の生成を行うC言語によるサンプルプログラムです。 本サンプルは以下に示されるデータ点から補間値を求めて出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_2d_shep_interp() のExampleコードです。本サンプル及び関数の詳細情報は nag_2d_shep_interp のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_2d_shep_interp のマニュアルページを参照)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
このデータをダウンロード |
nag_2d_shep_interp (e01sgc) Example Program Data 30 M, the number of data points 11.16 1.24 22.15 X, Y, F data point definition 12.85 3.06 22.11 19.85 10.72 7.97 19.72 1.39 16.83 15.91 7.74 15.30 0.00 20.00 34.60 20.87 20.00 5.74 3.45 12.78 41.24 14.26 17.87 10.74 17.43 3.46 18.60 22.80 12.39 5.47 7.58 1.98 29.87 25.00 11.87 4.40 0.00 0.00 58.20 9.66 20.00 4.73 5.22 14.66 40.36 17.25 19.57 6.43 25.00 3.87 8.74 12.13 10.79 13.71 22.23 6.21 10.25 11.52 8.53 15.74 15.20 0.00 21.60 7.54 10.69 19.31 17.32 13.78 12.11 2.14 15.03 53.10 0.51 8.37 49.43 22.69 19.63 3.25 5.47 17.13 28.63 21.67 14.36 5.52 3.31 0.33 44.08 End of data points 5 N, the number of evaluation points 20.00 3.14 U, V evaluation point definition 6.41 15.44 7.54 10.69 9.91 18.27 12.30 9.22 End of evaluation points
- 1行目はタイトル行で読み飛ばされます。
- 2行目にデータ点の数(m)を指定しています。
- 3~32行目にはデータ点の座標x、yとデータ値(f)を指定しています。
- 33行目には評価点の数(n)を指定しています。
- 34~38行目に評価点(u,v)を指定しています。
出力結果
(本関数の詳細はnag_2d_shep_interp のマニュアルページを参照)1 2 3 4 5 6 7 8
この出力例をダウンロード |
nag_2d_shep_interp (e01sgc) Example Program Results I U(I) V(I) Q(I) 1 20.00 3.14 15.89 2 6.41 15.44 34.05 3 7.54 10.69 19.31 4 9.91 18.27 13.68 5 12.30 9.22 14.56
- 3~8行目に評価点と補間値が出力されています。
ソースコード
(本関数の詳細はnag_2d_shep_interp のマニュアルページを参照)
※本サンプルソースコードは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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
このソースコードをダウンロード |
/* nag_2d_shep_interp (e01sgc) 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 <nage01.h> int main(void) { /* Scalars */ Integer exit_status, i, m, n, nq, nw; Integer liq, lrq; /* Arrays */ double *f = 0, *q = 0, *qx = 0, *qy = 0, *rq = 0, *u = 0, *v = 0, *x = 0; double *y = 0; Integer *iq = 0; /* Nag Types */ NagError fail; exit_status = 0; INIT_FAIL(fail); printf("nag_2d_shep_interp (e01sgc) Example Program Results\n\n"); /* Skip heading in data file */ scanf("%*[^\n] "); /* Input the number of nodes. */ scanf("%ld%*[^\n] ", &m); if (m > 6) { liq = 2 * m + 1; lrq = 6 * m + 5; /* Allocate memory */ if (!(f = nAG_ALLOC(m, double)) || !(rq = nAG_ALLOC(lrq, double)) || !(x = nAG_ALLOC(m, double)) || !(y = nAG_ALLOC(m, double)) || !(iq = nAG_ALLOC(liq, Integer))) { printf("Allocation failure\n"); exit_status = -1; goto END; } } else { printf("Invalid m.\n"); exit_status = 1; return exit_status; } /* Input the data points X,Y and F. */ for (i = 1; i <= m; ++i) { scanf("%lf%lf%lf%*[^\n] ", &x[i - 1], &y[i - 1], &f[i - 1]); } /* Generate the interpolant. */ nq = 0; nw = 0; /* nag_2d_shep_interp (e01sgc). * Interpolating functions, modified Shepard's method, two * variables */ nag_2d_shep_interp(m, x, y, f, nw, nq, iq, rq, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_2d_shep_interp (e01sgc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Input the number of evaluation points. */ scanf("%ld%*[^\n] ", &n); if (!(q = nAG_ALLOC(n, double)) || !(qx = nAG_ALLOC(n, double)) || !(qy = nAG_ALLOC(n, double)) || !(u = nAG_ALLOC(n, double)) || !(v = nAG_ALLOC(n, double))) { printf("Allocation failure\n"); exit_status = 1; goto END; } /* Input the evaluation points. */ for (i = 1; i <= n; ++i) { scanf("%lf%lf%*[^\n] ", &u[i - 1], &v[i - 1]); } /* Evaluate the interpolant using nag_2d_shep_eval (e01shc). */ /* nag_2d_shep_eval (e01shc). * Interpolated values, evaluate interpolant computed by * nag_2d_shep_interp (e01sgc), function and first * derivatives, two variables */ nag_2d_shep_eval(m, x, y, f, iq, rq, n, u, v, q, qx, qy, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_2d_shep_interp (e01sgc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("%s", " I U(I) V(I) Q(I)"); printf("\n"); for (i = 1; i <= n; ++i) { printf("%6ld%10.2f%10.2f%10.2f\n", i, u[i - 1], v[i - 1], q[i - 1]); } END: nAG_FREE(f); nAG_FREE(q); nAG_FREE(qx); nAG_FREE(qy); nAG_FREE(rq); nAG_FREE(u); nAG_FREE(v); nAG_FREE(x); nAG_FREE(y); nAG_FREE(iq); return exit_status; }