/************************************************************************* Unpack testing *************************************************************************/ private static bool testunpack(ref spline1d.spline1dinterpolant c, ref double[] x) { bool result = new bool(); int i = 0; int n = 0; double err = 0; double t = 0; double v1 = 0; double v2 = 0; int pass = 0; int passcount = 0; double[,] tbl = new double[0,0]; passcount = 20; err = 0; spline1d.spline1dunpack(ref c, ref n, ref tbl); for(i=0; i<=n-2; i++) { for(pass=1; pass<=passcount; pass++) { t = AP.Math.RandomReal()*(tbl[i,1]-tbl[i,0]); v1 = tbl[i,2]+t*tbl[i,3]+AP.Math.Sqr(t)*tbl[i,4]+t*AP.Math.Sqr(t)*tbl[i,5]; v2 = spline1d.spline1dcalc(ref c, tbl[i,0]+t); err = Math.Max(err, Math.Abs(v1-v2)); } } for(i=0; i<=n-2; i++) { err = Math.Max(err, Math.Abs(x[i]-tbl[i,0])); } for(i=0; i<=n-2; i++) { err = Math.Max(err, Math.Abs(x[i+1]-tbl[i,1])); } result = (double)(err)<(double)(100*AP.Math.MachineEpsilon); return result; }
/************************************************************************* Unset spline, i.e. initialize it with random garbage *************************************************************************/ private static void unsetspline1d(ref spline1d.spline1dinterpolant c) { double[] x = new double[0]; double[] y = new double[0]; double[] d = new double[0]; x = new double[2]; y = new double[2]; d = new double[2]; x[0] = -1; y[0] = AP.Math.RandomReal(); d[0] = AP.Math.RandomReal(); x[1] = 1; y[1] = AP.Math.RandomReal(); d[1] = AP.Math.RandomReal(); spline1d.spline1dbuildhermite(x, y, d, 2, ref c); }
/************************************************************************* Lipschitz constants for spline inself, first and second derivatives. *************************************************************************/ private static void lconst(double a, double b, ref spline1d.spline1dinterpolant c, double lstep, ref double l0, ref double l1, ref double l2) { double t = 0; double vl = 0; double vm = 0; double vr = 0; double prevf = 0; double prevd = 0; double prevd2 = 0; double f = 0; double d = 0; double d2 = 0; l0 = 0; l1 = 0; l2 = 0; t = a-0.1; vl = spline1d.spline1dcalc(ref c, t-2*lstep); vm = spline1d.spline1dcalc(ref c, t-lstep); vr = spline1d.spline1dcalc(ref c, t); f = vm; d = (vr-vl)/(2*lstep); d2 = (vr-2*vm+vl)/AP.Math.Sqr(lstep); while( (double)(t)<=(double)(b+0.1) ) { prevf = f; prevd = d; prevd2 = d2; vl = vm; vm = vr; vr = spline1d.spline1dcalc(ref c, t+lstep); f = vm; d = (vr-vl)/(2*lstep); d2 = (vr-2*vm+vl)/AP.Math.Sqr(lstep); l0 = Math.Max(l0, Math.Abs((f-prevf)/lstep)); l1 = Math.Max(l1, Math.Abs((d-prevd)/lstep)); l2 = Math.Max(l2, Math.Abs((d2-prevd2)/lstep)); t = t+lstep; } }