Keyword: 最小二乗, チェビシェフ級数, フィット
概要
本サンプルは最小二乗チェビシェフ級数曲面フィットを行うFortranによるサンプルプログラムです。 本サンプルは以下に示されるデータについてフィットされた値とチェビシェフ係数を求めて出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン e02caf() のExampleコードです。本サンプル及びルーチンの詳細情報は e02caf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はe02caf のマニュアルページを参照)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
このデータをダウンロード |
E02CAF Example Program Data 4 3 2 0.0 8 0.0 5.0 1.0 7 0.1 4.5 2.0 7 0.4 4.0 4.0 6 1.6 3.5 0.1 1.01005 1.0 1.0 1.10517 1.0 1.6 1.17351 1.0 2.1 1.23368 1.0 3.3 1.39097 1.0 3.9 1.47698 1.0 4.2 1.52196 1.0 4.9 1.63232 1.0 0.1 2.02010 1.0 1.1 2.23256 1.0 1.9 2.41850 1.0 2.7 2.61993 1.0 3.2 2.75426 1.0 4.1 3.01364 1.0 4.5 3.13662 1.0 0.5 3.15381 1.0 1.1 3.34883 1.0 1.3 3.41649 1.0 2.2 3.73823 1.0 2.9 4.00928 1.0 3.5 4.25720 1.0 3.9 4.43094 1.0 1.7 5.92652 1.0 2.0 6.10701 1.0 2.4 6.35625 1.0 2.7 6.54982 1.0 3.1 6.81713 1.0 3.5 7.09534 1.0
- 1行目はタイトル行で読み飛ばされます。
- 2行目にデータが与えられる Y=Y(I)の行の数(n)、x方向のフィットの次数(k)、y方向のフィットの次数(l)を指定しています。
- 3~6行目にはYの値、データ点の数(m)、xの範囲の下限(xmin)、上限(xmax)を指定しています。
- 7~34行目にはデータ点のx値、従属変数のデータ値(f)、データ点に割り当てられた重み(w)を指定しています。
出力結果
(本ルーチンの詳細はe02caf のマニュアルページを参照)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
この出力例をダウンロード |
E02CAF Example Program Results Data Y Data X Data F Fitted F Residual 0.0000 0.1000 1.0100 1.0175 0.74E-02 0.0000 1.0000 1.1052 1.1126 0.74E-02 0.0000 1.6000 1.1735 1.1809 0.74E-02 0.0000 2.1000 1.2337 1.2412 0.75E-02 0.0000 3.3000 1.3910 1.3992 0.82E-02 0.0000 3.9000 1.4770 1.4857 0.87E-02 0.0000 4.2000 1.5220 1.5310 0.90E-02 0.0000 4.9000 1.6323 1.6422 0.98E-02 1.0000 0.1000 2.0201 1.9987 -0.21E-01 1.0000 1.1000 2.2326 2.2110 -0.22E-01 1.0000 1.9000 2.4185 2.3962 -0.22E-01 1.0000 2.7000 2.6199 2.5966 -0.23E-01 1.0000 3.2000 2.7543 2.7299 -0.24E-01 1.0000 4.1000 3.0136 2.9869 -0.27E-01 1.0000 4.5000 3.1366 3.1084 -0.28E-01 2.0000 0.5000 3.1538 3.1700 0.16E-01 2.0000 1.1000 3.3488 3.3648 0.16E-01 2.0000 1.3000 3.4165 3.4325 0.16E-01 2.0000 2.2000 3.7382 3.7549 0.17E-01 2.0000 2.9000 4.0093 4.0272 0.18E-01 2.0000 3.5000 4.2572 4.2769 0.20E-01 2.0000 3.9000 4.4309 4.4521 0.21E-01 4.0000 1.7000 5.9265 5.9231 -0.34E-02 4.0000 2.0000 6.1070 6.1036 -0.34E-02 4.0000 2.4000 6.3563 6.3527 -0.35E-02 4.0000 2.7000 6.5498 6.5462 -0.36E-02 4.0000 3.1000 6.8171 6.8132 -0.40E-02 4.0000 3.5000 7.0953 7.0909 -0.45E-02 Chebyshev coefficients of the fit 15.3482 5.1507 0.1014 1.1472 0.1442 -0.1046 0.0490 -0.0031 -0.0070 0.0015 -0.0003 -0.0002
- 3~35行目にy値、x値、従属変数のデータ値、フィットされたデータ値及び残差が出力されています。
- 37~42行目にチェビシェフ係数が出力されています。
ソースコード
(本ルーチンの詳細はe02caf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
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
このソースコードをダウンロード |
PROGRAM e02cafe ! E02CAF Example Program Text ! Mark 23 Release. nAG Copyright 2011. ! .. Use Statements .. USE nag_library, ONLY : e02caf, e02cbf, nag_wp ! .. Implicit None Statement .. IMPLICIT NONE ! .. Parameters .. INTEGER, PARAMETER :: nin = 5, nout = 6 ! .. Local Scalars .. REAL (KIND=nag_wp) :: ymax INTEGER :: i, ifail, inuxp1, inuyp1, j, k, l, & mi, mtot, n, na, nwork, r, t ! .. Local Arrays .. REAL (KIND=nag_wp), ALLOCATABLE :: a(:), f(:), ff(:), nux(:), nuy(:), & w(:), work(:), x(:), xmax(:), & xmin(:), y(:) INTEGER, ALLOCATABLE :: m(:) ! .. Intrinsic Functions .. INTRINSIC max, sum ! .. Executable Statements .. WRITE (nout,*) 'E02CAF Example Program Results' ! Skip heading in data file READ (nin,*) ! Input the number of lines Y = Y(I) on which data is given, ! and the required degree of fit in the X and Y directions READ (nin,*) n, k, l inuxp1 = 1 inuyp1 = 1 na = (k+1)*(l+1) ALLOCATE (a(na),m(n),y(n),xmin(n),xmax(n),nux(inuxp1),nuy(inuyp1)) ! Input Y(I), the number of data points on Y = Y(I) and the ! range of X-values on this line, for I = 1,2,...N DO i = 1, n READ (nin,*) y(i), m(i), xmin(i), xmax(i) END DO mtot = sum(m(1:n)) nwork = 3*mtot + 2*n*(k+2) + 5*(1+max(k,l)) ALLOCATE (x(mtot),f(mtot),w(mtot),ff(mtot),work(nwork)) ! Input the X-values and function values, F, together with ! their weights, W. READ (nin,*) (x(i),f(i),w(i),i=1,mtot) ! Evaluate the coefficients, A, of the fit to this set of data ifail = 0 CALL e02caf(m,n,k,l,x,y,f,w,mtot,a,na,xmin,xmax,nux,inuxp1,nuy,inuyp1, & work,nwork,ifail) mi = 0 WRITE (nout,*) WRITE (nout,*) & ' Data Y Data X Data F Fitted F Residual' WRITE (nout,*) DO r = 1, n t = mi + 1 mi = mi + m(r) ymax = y(n) IF (n==1) THEN ymax = ymax + 1.0E0_nag_wp END IF ! Evaluate the fitted polynomial at each of the data points ! on the line Y = Y(R) ifail = 0 CALL e02cbf(t,mi,k,l,x,xmin(r),xmax(r),y(r),y(1),ymax,ff,a,na,work, & nwork,ifail) ! Output the data and fitted values on the line Y = Y(R) DO i = t, mi WRITE (nout,99999) y(r), x(i), f(i), ff(i), ff(i) - f(i) END DO WRITE (nout,*) END DO ! Output the Chebyshev coefficients of the fit WRITE (nout,*) 'Chebyshev coefficients of the fit' WRITE (nout,*) DO j = 1, k + 1 WRITE (nout,99998) (a(i),i=1+(j-1)*(l+1),j*(l+1)) END DO 99999 FORMAT (3X,4F11.4,E11.2) 99998 FORMAT (1X,6F11.4) END PROGRAM e02cafe