我使用这些代码进行双三次样条插值,并使用函数
`spline2ddiff(s, vx, vy, v, dx, dy, dxy);`
可以得到一阶导数和混合的二阶导数,如何得到二阶导数?
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "interpolation.h"
#define N 4
using namespace alglib;
int main(int argc, char **argv)
{
//
// We use bilinear spline to interpolate f(x,y)=x^2+2*y^2 sampled
// at (x,y) from [0.0, 0.5, 1.0] X [0.0, 1.0].
//
int i,j,k;
real_1d_array x ;
x.setlength(N);
real_1d_array y ;
y.setlength(N);
real_1d_array f ;
f.setlength(N*N);
double h = 2.0/(N-1);
for (i = 0; i<N; i++) {
x[i] = -1.0+i*h;
y[i] = -1.0+i*h;
}
//real_1d_array y = "[0.0, 1.0]";
for (i=0; i<N; i++) {
for (j=0; j<N; j++) {
//f[i*N+j] = 4*pow((double)x[j],2)+3*pow((double)y[i],2);
f[i*N+j] = 1+2*y[i]+3*y[i]*y[i]+4*y[i]*y[i]*y[i]+5*x[j]+6*x[j]*y[i]\
+7*x[j]*y[i]*y[i]+8*x[j]*y[i]*y[i]*y[i]+9*x[j]*x[j]+10*x[j]*x[j]*y[i]+11*x[j]*x[j]*y[i]*y[i]+12*x[j]*x[j]*y[i]*y[i]*y[i]+13*x[j]*x[j]*x[j]+14*x[j]*x[j]*x[j]*y[i]+15*x[j]*x[j]*x[j]*y[i]*y[i]+16*x[j]*x[j]*x[j]*y[i]*y[i]*y[i];
}
}
real_2d_array c;
real_1d_array c1;
c1.setlength(20);
ae_int_t m;
ae_int_t n;
ae_int_t d;
double vx = 0.25;
double vy = 0.50;
double v;
double dx;
double dy;
double dxy;
spline2dinterpolant s;
// build spline
spline2dbuildbicubicv(x, N, y, N, f, 1, s);
// unpack and test
spline2dunpackv(s, m, n, d, c);
for (i=0; i<20; i++) {
c1[i] = c[0][i];
}
printf("%s\n", c.tostring(0).c_str()); // EXPECTED: [[0, 1, 0, 1, 0,2,0,0, 1,3,0,0, 0,0,0,0, 0,0,0,0 ]]
// calculate S(0.25,0.50)
v = spline2dcalc(s, vx, vy);
printf("%.10f\n", double(v)); // EXPECTED: 1.0625
// calculate derivatives
spline2ddiff(s, vx, vy, v, dx, dy, dxy);
printf("%.10f\n", double(v)); // EXPECTED: 1.0625
printf("%.10f\n", double(dx)); // EXPECTED: 0.5000
printf("%.10f\n", double(dy)); // EXPECTED: 2.0000
printf("%.10f\n", double(dxy));
return 0;
}
我不知道是否有某些功能可以直接执行此操作?而且我不知道返回的系数均值,双三次样条插值应该有16个系数,但是有20个。