📄 ocn_e01.h
字号:
/*------------------------------------------------------------------------------*
* 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 <NAG\nag_types.h>
/** 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<m; ++i)
y[i] = exp(x[i]);
nag_1d_spline_interpolant(m, x, y, &spline);
//put the result back to the worksheet.
yy = y;
Example2:
The following example program sets up data from 7 values of the exponential
function in the interval 0 to 1. nag 1d spline interpolant is then called
to compute a spline interpolant to these data. The spline is evaluated
by nag 1d spline evaluate (e02bbc), at the data points and at points halfway
between each adjacent pair of data points, and the spline values and
the values of ex are printed out.
void test_nag_1d_spline_interpolant()
{
int MMAX = 7;
double x[] = {0.0, 0.2, 0.4, 0.6, 0.75, 0.9, 1.0};
int i, j;
double y[7], fit, xarg;
Nag_Spline spline;
int m = MMAX;
for (i=0; i<m; ++i)
y[i] = exp(x[i]);
nag_1d_spline_interpolant(m, x, y, &spline);
printf("\n Number of distinct knots = %ld\n\n", m-2);
printf(" Distinct knots located at \n\n");
for (j=3; j<m+1; j++)
{
printf("%7.4f",spline.lamda[j]);
if((j-3)%5==4 || j==m )
printf("\n");
}
printf("\n\n J B-spline coeff c\n\n");
for (j=0; j<m; ++j)
printf(" %ld %13.4f\n",j+1,spline.c[j]);
printf("\n J Abscissa Ordinate Spline\n\n");
for (j=0; j<m; ++j)
{
nag_1d_spline_evaluate(x[j], &fit, &spline);
printf(" %ld %13.4f %13.4f %13.4f\n",j+1,x[j],y[j],fit);
if (j < m-1)
{
xarg = (x[j] + x[j+1]) * 0.5;
nag_1d_spline_evaluate(xarg, &fit, &spline);
printf(" %15.4f %27.4f\n",xarg,fit);
}
}
nag_free(spline.lamda);
nag_free(spline.c);
}
The output is as follows:
Number of distinct knots = 5
Distinct knots located at
0.0000 0.4000 0.6000 0.7500 1.0000
J B-spline coeff c
1 1.0000
2 1.1336
3 1.3726
4 1.7827
5 2.1744
6 2.4918
7 2.7183
J Abscissa Ordinate Spline
1 0.0000 1.0000 1.0000
0.1000 1.1052
2 0.2000 1.2214 1.2214
0.3000 1.3498
3 0.4000 1.4918 1.4918
0.5000 1.6487
4 0.6000 1.8221 1.8221
0.6750 1.9640
5 0.7500 2.1170 2.1170
0.8250 2.2819
6 0.9000 2.4596 2.4596
0.9500 2.5857
7 1.0000 2.7183 2.7183
Parameters:
Return:
This function returns NAG error code, 0 if no error.
11: On entry, m must not be less than 4: m = _value_.
63: The sequence x is not strictly increasing: x[_value_] = _value_, x[_value_] = _value_.
73: Memory allocation failed.
successful call of the nag_1d_spline_interpolant function.
*/
int nag_1d_spline_interpolant(
int m, // the number of data points.
double x[], // the ith data value of the independent variable x, for i = 1, 2, . . .,m.
double y[], // the ith data value of the dependent variable y, for i = 1, 2, . . .,m.
Nag_Spline *spline
);
/** e01bec
computes a monotonicity-preserving piecewise cubic Hermite interpolant to a set of data points.
Example1:
Assume "Data1" Worksheet has 5 columns, the first 2 columns contain 9 data in each column
and we want to put result in the third, 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(m);
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;
if(0 == nag_monotonic_interpolant(n, x, f, d))
{
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);
//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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -