/*------------------------------------------------------------------------------* * File Name: OCN_e01.h * * Creation: TCZ 8/1/2001 * * Purpose: Origin C Header for NAG functions * * Copyright (c) OriginLab Corp. 2001 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #ifndef NAGE01 #define NAGE01 //#importdll "ONAG" // NAG DLL prepared by OriginLab #pragma dll(ONAG) #include /** e01bac determines a cubic spline interpolant to a given set of data. Example1: Assume "Data1" Worksheet has 2 columns, the first column contain 5 data and we want to put result in the second column. int m = 5, i, j; Nag_Spline spline; //Attach two Datasets to these 2 columns Dataset xx("data1",0); xx.SetSize(m); Dataset yy("data1",1); yy.SetSize(m); //Because Dataset cannot be the parameter of function, but vector can be. vector x = xx, y = yy; for (i=0; i x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_evaluate(n, x, f, d, m, px, pf); //write the result back to the worksheet. dd = d; dpf = pf; dpx = px; } else printf("there is some problem with the function of nag_monotonic_interpolant"); Example2: This example program reads in a set of data points, calls nag monotonic interpolant to compute a piecewise monotonic interpolant, and then calls nag monotonic evaluate (e01bfc) to evaluate the interpolant at equally spaced points. void test_nag_monotonic_interpolant() { int i, m, n, r; double step, d[50], pf[50], px[50]; n = 9; double x[50] = {7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00}; double f[50] = {0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0, 0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0}; if(0 == nag_monotonic_interpolant(n, x, f, d)) { m = 11; step = (x[n-1] - x[0]) / (1.0*(m-1)); for (i = 0; i < m; i++) { if(x[0]+ i*step > x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_evaluate(n, x, f, d, m, px, pf); printf(" Interpolated\n"); printf(" Abscissa Value\n"); for (i = 0; i < m; i++) printf("%13.4f%13.4f\n", px[i], pf[i]); } else printf("there is some problem with the function of nag_monotonic_interpolant"); } The output is as follows: Interpolated Abscissa Value 7.9900 0.0000 9.1910 0.4640 10.3920 0.9645 11.5930 0.9965 12.7940 0.9992 13.9950 0.9998 15.1960 0.9999 16.3970 1.0000 17.5980 1.0000 18.7990 1.0000 20.0000 1.0000 Parameters: Return: This function returns NAG error code, 0 if no error. 11: On entry, n must not be less than 2: n = _value_. 236: On entry, x[r - 1] = x[r] for r = _value_: x[r - 1], x[r] = _values_. The values of x[r], for r = 0, 1, . . . , n - 1, are not in strictly increasing order. successful call of the nag_monotonic_interpolant function. */ int nag_monotonic_interpolant( int n, // the number of data points. double x[], // the rth value of the independent variable (abscissa), for r = 0, 1 . . . , n - 1. double f[], // the rth value of the dependent variable (ordinate), for r = 0, 1, . . . , n - 1. double d[] // d[r] contains the derivative at x[r]. ); /** e01bfc evaluates a piecewise cubic Hermite interpolant at a set of points. Example1: Assume "Data1" Worksheet has 5 columns, the first 3 columns contain 9 data in each column and we want to put result in the fourth and fifth column. int i, m = 11, n = 9, r; //Attach four Datasets to these 5 columns Dataset dx("data1",0); dx.SetSize(n); Dataset df("data1",1); df.SetSize(n); Dataset dd("data1",2); dd.SetSize(n); Dataset dpf("data1",3); dpf.SetSize(m); Dataset dpx("data1",4); dpx.SetSize(m); //vector can be a parameter, but Dataset cannot. vector x = dx, f = df, d = dd, pf = dpf, px = dpx; double step = (x[n-1] - x[0]) / (1.0*(m-1)); for (i = 0; i < m; i++) { if(x[0]+ i*step > x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_evaluate(n, x, f, d, m, px, pf); //put the result back to worksheet. dpf = pf; dpx = px; Example2: This example program reads in values of n, x, f, d and m, and then calls nag monotonic evaluate to evaluate the interpolant at equally spaced points. void test_nag_monotonic_evaluate() { int i, m, n, r; double step, pf[50], px[50]; n = 9; m = 11; double x[50] = {7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00}; double f[50] = {0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0, 0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0}; double d[50] = {0.00000E+0, 5.52510E-4, 0.33587E+0, 0.34944E+0, 0.59696E+0, 6.03260E-2, 8.98335E-4, 2.93954E-5, 0.00000E+0}; step = (x[n-1] - x[0]) / (1.0*(m-1)); for (i = 0; i < m; i++) { if(x[0]+ i*step > x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_evaluate(n, x, f, d, m, px, pf); printf(" Interpolated\n"); printf(" Abscissa Value\n"); for (i = 0; i < m; i++) printf("%13.4f%13.4f\n", px[i], pf[i]); } The output is as follows: Interpolated Abscissa Value 7.9900 0.0000 9.1910 0.4640 10.3920 0.9645 11.5930 0.9965 12.7940 0.9992 13.9950 0.9998 15.1960 0.9999 16.3970 1.0000 17.5980 1.0000 18.7990 1.0000 20.0000 1.0000 Parameters: Return: This function returns NAG error code, 0 if no error. 11: On entry, n must not be less than 2: n = _value_. On entry, m must not be less than 1: m = _value_. 236: On entry, x[r - 1] = x[r] for r = _value_: x[r - 1], x[r] = _values_. The values of x[r], for r = 0, 1, . . . , n - 1, are not in strictly increasing order. 237: Warning - some points in array PX lie outside the range x[0]. . .x[n - 1]. Values at these points are unreliable as they have been computed by extrapolation. successful call of the nag_monotonic_evaluate function. */ int nag_monotonic_evaluate( int n, double x[], double f[], double d[], // Input: n, x, f and d must be unchanged from the previous call of nag monotonic interpolant (e01bec). int m, // the number of points at which the interpolant is to be evaluated. double px[], // Input: the m values of x at which the interpolant is to be evaluated. double pf[] // Output: pf[i] contains the value of the interpolant evaluated at the point px[i], for i = 0, 1 . . .,m - 1. ); /** e01bgc evaluates a piecewise cubic Hermite interpolant and its first derivative at a set of points. Example1: Assume "Data1" Worksheet has 6 columns and 10 rows, the first 3 columns contain 5 data in each column and we want to put result in the fourth to sixth column. int i, m = 7, n = 5, r; double step; //Attach six Datasets to these 6 columns Dataset dx("data1",0); dx.SetSize(n); Dataset df("data1",1); df.SetSize(n); Dataset dd("data1",2); dd.SetSize(n); Dataset dpf("data1",3); dpf.SetSize(m); Dataset dpx("data1",4); dpx.SetSize(m); Dataset dpd("data1",5); dpd.SetSize(m); //vector can be a parameter, but Dataset cannot. vector x = dx, f = df, d = dd, pf = dpf, px = dpx, pd = dpd; step = (x[n-1]-x[0]) / (double)(m-1); for (i = 0; i < m; i++) { if(x[0]+ i*step > x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_deriv(n, x, f, d, m, px, pf, pd); //Put the results to the Worksheet. dpf = pf; dpx = px; dpd = pd; Example2: This example program reads in values of n, x, f and d and calls nag monotonic deriv to compute the values of the interpolant and its derivative at equally spaced points. void test_nag_monotonic_deriv() { int i, m, n, r; double pd[21], pf[21], px[21], step; n = 9; m = 11; double x[50] = {7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00}; double f[50] = {0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0, 0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0}; double d[50] = {0.00000E+0, 5.52510E-4, 0.33587E+0, 0.34944E+0, 0.59696E+0, 6.03260E-2, 8.98335E-4, 2.93954E-5, 0.00000E+0}; step = (x[n-1]-x[0]) / (double)(m-1); for (i = 0; i < m; i++) { if(x[0]+ i*step > x[n-1]) px[i] =x[n-1]; else px[i] = x[0]+ i*step; } nag_monotonic_deriv(n, x, f, d, m, px, pf, pd); printf(" Interpolated Interpolated\n"); printf(" Abscissa Value Derivative\n"); for (i=0; i xhi) tx[i] = xhi; else tx[i] = xlo + i * step; printf(" %5.2f ",tx[i]); } step = (yhi-ylo)/(npy-1); for (i=0; i yhi) ty[i] = yhi; else ty[i] = ylo + i * step; } nag_2d_spline_eval_rect(npx, npy, tx, ty, fg, &spline); printf("\n"); for (j=0; j= 0; --i) { printf("%8.2f ", py[nx * i]); for (j = 0; j < nx; j++) printf("%8.2f", pf[nx * i + j]); printf("\n"); } nag_2d_scat_free(&comm); } } The output is as follows: px 3.00 6.00 9.00 12.00 15.00 18.00 21.00 py pf 17.00 41.25 27.62 18.03 12.29 11.68 9.09 5.37 14.00 47.61 36.66 22.87 14.02 13.44 11.20 6.46 11.00 38.55 25.25 16.72 13.83 13.08 10.71 6.88 8.00 37.90 23.97 16.79 16.43 15.46 13.02 9.30 5.00 40.49 29.26 22.51 20.72 19.30 16.72 12.87 2.00 43.52 33.91 26.59 22.23 21.15 18.67 14.88 optional.rnw = 9.49 optional.rnq = 13.42 minimum number of data points that lie within radius optional.rnq = 7 px 3.00 6.00 9.00 12.00 15.00 18.00 21.00 py pf 17.00 40.23 27.72 21.23 14.59 12.00 9.43 5.46 14.00 46.96 37.37 23.74 14.67 13.25 11.29 6.26 11.00 39.42 25.42 16.32 13.78 12.60 10.39 7.03 8.00 37.50 22.36 18.57 15.63 15.55 13.05 9.69 5.00 41.25 31.76 24.74 21.17 18.93 16.83 12.65 2.00 44.58 34.35 26.47 22.27 20.98 18.69 15.06 Parameters: Return: This function returns NAG error code, 0 if no error. 70: On entry, parameter method had an illegal value. 11: On entry, m must not be less than 3: m = _value_. 73: Memory allocation failed. 245: On entry, all the (x,y) pairs are collinear. Consider specifying method = Nag Shep or usinga one-dimensional interpolating function nag 1d spline interpolant (e01bac). 246: On entry, each data pair is not unique since data points (x[_value_],y[_value_]) and (x[_value_],y[_value_]) are identical and equal to (_value_,_value_). 247: On entry, either or both of optional.nq and optional.nw are invalid, optional.nq = _value_ and optional.nw = _value_. optional.nq and optional.nw must satisfy the following constraints: 0 < optional.nw = optional.nq. 248: On entry, either or both of optional.rnq and optional.rnw are invalid, optional.rnq = _value_ and optional.rnw = _value_. optional.rnq and optional.rnw must satisfy the following constraints: 0.0 < optional.rnw = optional.rnq. 249: The minimum number of data points _value_ that lie within the radius optional.rnq of any node is small enough to indicate that the interpolant may be unsatisfactory in regions where the data points are sparse. Current values of other relevant parameters (available as members of the structure optional, if this has been defined) are rnq = _value_, rnw = _value_, nq = _value_, nw = _value_. successful call of the nag_2d_scat_interpolant function. */ int nag_2d_scat_interpolant( Nag_2d_Scat_Method method, int m, // the number of data points, m. double x[], // Input: the co-ordinates of the rth data point, for r = 1, 2, . . .,m. The data points are accepted in any order, but see Section 6. double y[], // Input: the co-ordinates of the rth data point, for r = 1, 2, . . .,m. The data points are accepted in any order, but see Section 6. double f[], // Input: the co-ordinates of the rth data point, for r = 1, 2, . . .,m. The data points are accepted in any order, but see Section 6. Nag_Scat_Struct *comm, // Pointer to a communication structure of type Nag Scat Struct. For method = Nag RC, this structure contains the computed triangulation and the estimated partial derivatives at the nodes. For method = Nag Shep, this structure contains the coefficients of the constructed nodal functions. This structure must be passed unchanged to the interpolant evaluating function nag 2d scat eval (e01sbc). Nag_E01_Opt *optional // Pointer to structure of type Nag E01 Opt, which may be used only if method = Nag Shep. ); /** e01sbc evaluates at given points the two-dimensional interpolant function computed by nag 2d scat interpolant (e01sac). Example: See the example program for nag 2d scat interpolant (e01sac). Parameters: Return: This function returns NAG error code, 0 if no error. 178: The setup function nag 2d scat interpolant (e01sac) has not been called. 179: The call to setup function nag 2d scat interpolant (e01sac) produced an error. 81: The structure _value_ has been corrupted since the previous call to _value_. 11: On entry, n must not be less than 1: n = _value_. 251: The evaluation point (_value_, _value_) of (px, py) lies outside the triangulation boundary. The returned value, _value_,of pf was computed by extrapolation. 252: On entry,the interpolant cannot be evaluted because the evaluation point (px, py) of (_value_, _value_) is outside the support region of the input data points defined by optional.rnw= _value_ as set in nag 2d scat interpolant (e01sac). successful call of the nag_2d_scat_eval function. */ int nag_2d_scat_eval( Nag_Scat_Struct *comm, // Pointer to a communication structure of type Nag Scat Struct which must be unchanged from the previous call of nag 2d scat interpolant (e01sac). int n, // the number of points at which the evaluation of the interpolant is required. double px[], double py[], // Input: the x- and y-coordinates of the kth point (pxk, pyk),fo r k = 1, 2, . . . ,n,at which the interpolant is to be evaluated. double pf[] // Output: the values of the interpolant evaluated at the points (pxk, pyk),fo r k = 1, 2, . . . ,n. ); /** e01szc frees the memory allocated by NAG function nag 2d scat interpolant (e01sac) to the communication structure comm of type Nag Scat Struct. Example: See nag 2d scat interpolant (e01sac) for an example of hown ag 2d scat free is used. Parameters: Return: This function returns NAG error code, 0 if no error. successful call of the nag_2d_scat_free function. */ void nag_2d_scat_free( Nag_Scat_Struct *comm // Input: the communication structure that was used in the call to nag 2d scat interpolant (e01sac). Output: pointers which pointed to NAG allocated memory will have been freed and set to NULL. ); #endif /* not NAGE01 */