int main(void) { int i,j; float d1,d2,ee,x1x2; float y[5],y1[5],y2[5],y12[5],**c; static float x1[]={0.0,0.0,2.0,2.0,0.0}; static float x2[]={0.0,0.0,0.0,2.0,2.0}; c=matrix(1,4,1,4); d1=x1[2]-x1[1]; d2=x2[4]-x2[1]; for (i=1;i<=4;i++) { x1x2=x1[i]*x2[i]; ee=exp(-x1x2); y[i]=x1x2*ee; y1[i]=x2[i]*(1.0-x1x2)*ee; y2[i]=x1[i]*(1.0-x1x2)*ee; y12[i]=(1.0-3.0*x1x2+x1x2*x1x2)*ee; } bcucof(y,y1,y2,y12,d1,d2,c); printf("\nCoefficients for bicubic interpolation:\n\n"); for (i=1;i<=4;i++) { for (j=1;j<=4;j++) printf("%12.6f",c[i][j]); printf("\n"); } free_matrix(c,1,4,1,4); return 0; }
void bcuint(float y[], float y1[], float y2[], float y12[], float x1l, float x1u, float x2l, float x2u, float x1, float x2, float *ansy, float *ansy1, float *ansy2) { void bcucof(float y[], float y1[], float y2[], float y12[], float d1, float d2, float **c); int i; float t,u,d1,d2,**c; c=matrix(1,4,1,4); d1=x1u-x1l; d2=x2u-x2l; bcucof(y,y1,y2,y12,d1,d2,c); if (x1u == x1l || x2u == x2l) nrerror("Bad input in routine bcuint"); t=(x1-x1l)/d1; u=(x2-x2l)/d2; *ansy=(*ansy2)=(*ansy1)=0.0; for (i=4;i>=1;i--) { *ansy=t*(*ansy)+((c[i][4]*u+c[i][3])*u+c[i][2])*u+c[i][1]; *ansy2=t*(*ansy2)+(3.0*c[i][4]*u+2.0*c[i][3])*u+c[i][2]; *ansy1=u*(*ansy1)+(3.0*c[4][i]*t+2.0*c[3][i])*t+c[2][i]; } *ansy1 /= d1; *ansy2 /= d2; free_matrix(c,1,4,1,4); }
void NR::bcuint(Vec_I_DP &y, Vec_I_DP &y1, Vec_I_DP &y2, Vec_I_DP &y12, const DP x1l, const DP x1u, const DP x2l, const DP x2u, const DP x1, const DP x2, DP &ansy, DP &ansy1, DP &ansy2) { int i; DP t,u,d1,d2; Mat_DP c(4,4); d1=x1u-x1l; d2=x2u-x2l; bcucof(y,y1,y2,y12,d1,d2,c); if (x1u == x1l || x2u == x2l) nrerror("Bad input in routine bcuint"); t=(x1-x1l)/d1; u=(x2-x2l)/d2; ansy=ansy2=ansy1=0.0; for (i=3;i>=0;i--) { ansy=t*ansy+((c[i][3]*u+c[i][2])*u+c[i][1])*u+c[i][0]; ansy2=t*ansy2+(3.0*c[i][3]*u+2.0*c[i][2])*u+c[i][1]; ansy1=u*ansy1+(3.0*c[3][i]*t+2.0*c[2][i])*t+c[1][i]; } ansy1 /= d1; ansy2 /= d2; }
void bcuint(double y[], double y1[], double y2[], double y12[], double x1l, double x1u, double x2l, double x2u, double x1, double x2, double *ansy, double *ansy1, double *ansy2, double *c) { //y--;y1--;y2--;y12--; int i; double t,u,d1,d2; d1=x1u-x1l; d2=x2u-x2l; bcucof(y,y1,y2,y12,d1,d2,c); //if (x1u == x1l || x2u == x2l) // nrerror("Bad input in routine bcuint"); t=(x1-x1l)/d1; u=(x2-x2l)/d2; *ansy=(*ansy2)=(*ansy1)=0.0; for (i=3;i>=0;i--) { *ansy=t*(*ansy)+((c[i*4+3]*u+c[i*4+2])*u+c[i*4+1])*u+c[i*4+0]; *ansy2=t*(*ansy2)+(3.0*c[i*4+3]*u+2.0*c[i*4+2])*u+c[i*4+1]; *ansy1=u*(*ansy1)+(3.0*c[3*4+i]*t+2.0*c[2*4+i])*t+c[1*4+i]; } *ansy1 /= d1; *ansy2 /= d2; }