// nuderiv3dg.java non uniformly spaced derivative coefficients // see nuderiv2dg.java for comments public class nuderiv3dg { int debug = 0; double AI[][] = new double[36][36]; // P then inverse double P[][] = new double[36][36]; int ordpt[] = {1, 4, 10, 20, 35}; int maxnpwr = 35; // max of 35 points used now, thus max of 4th order int xpow[] = {0, 1, 0, 0, 2, 1, 1, 0, 0, 0, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 4, 3, 3, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0}; int ypow[] = {0, 0, 1, 0, 0, 1, 0, 2, 1, 0, 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 4, 3, 2, 1, 0}; int zpow[] = {0, 0, 0, 1, 0, 0, 1, 0, 1, 2, 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 0, 1, 0, 1, 2, 0, 1, 2, 3, 0, 1, 2, 3, 4}; double xpwr[] = new double[5]; double ypwr[] = new double[5]; double zpwr[] = new double[5]; int okind = 0; // the number of x,y npoints must be at least sum i=1,order+1 of i // here, order means maximum order of terms used in computing cx, cy, ... // order 1 6 npoints only dx, dy // order 2 10 npoints only dxx, dxy, dyy and lower orders // order 3 20 npoints only dxxx, dxxy, dxyy, dyyy and lower orders // order 4 35 npoints only dxxxx, dxxxy, dxxyy, dxyyy, dyyyy, lower orders nuderiv3dg() { System.out.println("nuderiv3dg instantiated"); } // m is actual number of entries in c[] and ip[] // xpow[] and ypow[] are correct for the entries in c[] int nu3dx(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1) // cx { ci = (double)xpow[i]; xp = xpow[i]-1; // first derivative yp = ypow[i]; zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dx int nu3dy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1) // cy { ci = (double)ypow[i]; xp = xpow[i]; yp = ypow[i]-1; // first derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dy int nu3dz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1) // cz { ci = (double)zpow[i]; xp = xpow[i]; yp = ypow[i]; zp = zpow[i]-1; // first derivative c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dz int nu3dxx(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2) // cxx { ci = (double)xpow[i]*(double)(xpow[i]-1); xp = xpow[i]-2; // second derivative yp = ypow[i]; zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxx int nu3dxy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && ypow[i]>=1) // cxy { ci = (double)xpow[i]*(double)(ypow[i]); xp = xpow[i]-1; // first derivative yp = ypow[i]-1; // first derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxy int nu3dxz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && zpow[i]>=1) // cxz { ci = (double)xpow[i]*(double)(zpow[i]); xp = xpow[i]-1; // first derivative yp = ypow[i]; zp = zpow[i]-1; // first derivative c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxz int nu3dyy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2) // cyy { ci = (double)ypow[i]*(double)(ypow[i]-1); xp = xpow[i]; yp = ypow[i]-2; // second derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dyy int nu3dyz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && zpow[i]>=1) // cyz { ci = (double)ypow[i]*(double)zpow[i]; xp = xpow[i]; yp = ypow[i]-1; zp = zpow[i]-1; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dyz int nu3dzz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2) // czz { ci = (double)zpow[i]*(double)(zpow[i]-1); xp = xpow[i]; yp = ypow[i]; zp = zpow[i]-2; // second derivative c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dzz int nu3dxxx(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=3) // cxxx { ci = (double)xpow[i]*(double)(xpow[i]-1)*(double)(xpow[i]-2); xp = xpow[i]-3; // third derivative yp = ypow[i]; zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxxx int nu3dxxy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2 && ypow[i]>=1) // cxxy { ci = (double)xpow[i]*(double)(xpow[i]-1)*(double)(ypow[i]); xp = xpow[i]-2; // second derivative yp = ypow[i]-1; // first derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxxy int nu3dxxz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2 && zpow[i]>=1) // cxxz { ci = (double)xpow[i]*(double)(xpow[i]-1)*(double)(zpow[i]); xp = xpow[i]-2; yp = ypow[i]; zp = zpow[i]-1; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxxz int nu3dxyy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && ypow[i]>=2) // cxyy { ci = (double)xpow[i]*(double)(ypow[i])*(double)(ypow[i]-1); xp = xpow[i]-1; // first derivative yp = ypow[i]-2; // second derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxyy int nu3dxyz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && ypow[i]>=1 && zpow[i]>=1) // cxyz { ci = (double)xpow[i]*(double)(ypow[i])*(double)zpow[i]; xp = xpow[i]-1; yp = ypow[i]-1; zp = zpow[i]-1; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dxyz int nu3dyyy(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=3) // cyyy { ci = (double)ypow[i]*(double)(ypow[i]-1)*(double)(ypow[i]-2); xp = xpow[i]; yp = ypow[i]-3; // third derivative zp = zpow[i]; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dyyy int nu3dyyz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=2 && zpow[i]>=1) { ci = (double)ypow[i]*(double)(ypow[i]-1)*(double)zpow[i]; xp = xpow[i]; yp = ypow[i]-2; zp = zpow[i]-1; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dyyz int nu3dyzz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=1 && zpow[i]>=2) { ci = (double)ypow[i]*(double)zpow[i]*(double)(zpow[i]-1); xp = xpow[i]; yp = ypow[i]-1; zp = zpow[i]-2; c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dyzz int nu3dzzz(int order, int npoint, int point, double x[], double y[], double z[], double c[], int ip[]) { double ci; int xp, yp, zp, m; m = build(order, npoint, point, x, y, z, ip); for(int j=0; j=3) // czzz { ci = (double)zpow[i]*(double)(zpow[i]-1)*(double)(zpow[i]-2); xp = xpow[i]; yp = ypow[i]; zp = zpow[i]-3; // third derivative c[j] += ci*AI[i][j]*xpwr[xp]*ypwr[yp]*zpwr[zp]; } } } return m; } // end nu3dzzz int build(int order, int npoint, int point, double x[], double y[], double z[], int ip[]) { int sing; int n, n2i, nd, ni; double xa[] = new double[35]; double ya[] = new double[35]; double za[] = new double[35]; double tmp; debug = 0; // checks if(point<0 || point>=npoint) System.out.println("ERROR nuderiv3dg point outside range\n"); n2i = 1; // good points so far, this will become n nd = 0; // number deleted for(int i=0; i0) System.out.println("test_build added point "+point+" for index "+ (ni-1)+", nd="+nd); if(ni>=35) break; ni++; continue; } nd++; if(debug>0) System.out.println("test_build deleted point "+point+" for index "+ (ni-1)+", nd="+nd+", ni+nd="+(ni+nd)); if(ni+nd>=npoint) break; for(int nj=ni-1; nj0) { System.out.println("\n\nactual points selected\n"); for(int i=0; i abs_pivot) { I_pivot = i ; J_pivot = j ; pivot = A[row[i]][col[j]] ; } } } if(Math.abs(pivot) < 1.0E-12) { return 1; } hold = row[k]; row[k]= row[I_pivot]; row[I_pivot] = hold ; hold = col[k]; col[k]= col[J_pivot]; col[J_pivot] = hold ; // reduce about pivot A[row[k]][col[k]] = 1.0 / pivot ; for(int j=0; j