public static void main(String[] args) { float f = 0.0f; float d = 1.0f/3.0f; int n = 10000; double errorMaximum = 0.0; float x = f; for (int i=0; i<n; ++i,x+=d) { double xd = f+i*d; errorMaximum = max(errorMaximum,abs(xd-x)); } double errorEstimate = FLT_EPSILON*n*(abs(f)+abs(f+(n-1)*d))/2.0; System.out.println("error estimate ="+errorEstimate/d); System.out.println("error maximum ="+errorMaximum/d); } }
private static boolean almostEqual(double x1, double x2) { return abs(x1-x2)<=max(abs(x1),abs(x2))*100.0*DBL_EPSILON; } }
private static boolean almostEqual(double x, double y) { double ax = abs(x); double ay = abs(y); return abs(x-y)<=0.0001*max(ax,ay); } }
private void assertEquals(double e, double a) { double tiny = max(abs(e),abs(a))*100.0*DBL_EPSILON; assertEquals(e,a,tiny); } }
private static boolean almostEqual(double x, double y) { double ax = abs(x); double ay = abs(y); return abs(x-y)<=0.0001*max(ax,ay); } }
private void assertEquals(double expected, double actual) { double small = 1.0e-12f*max(abs(expected),abs(actual),1.0d); assertEquals(expected,actual,small); } }
private void assertEquals(float expected, float actual) { float small = 1.0e-6f*max(abs(expected),abs(actual),1.0f); assertEquals(expected,actual,small); }
private void assertEquals(float expected, float actual) { float small = 1.0e-6f*max(abs(expected),abs(actual),1.0f); assertEquals(expected,actual,small); }
/** * Constructs axis tics for a specified major tic interval. * @param x1 the value at one end of the axis. * @param x2 the value at the other end of the axis. * @param dtic the major tic interval; a positive number. */ public AxisTics(double x1, double x2, double dtic) { double xmin = min(x1,x2); double xmax = max(x1,x2); xmin -= (xmax-xmin)*FLT_EPSILON; xmax += (xmax-xmin)*FLT_EPSILON; double d = abs(dtic); double f = ceil(xmin/d)*d; //double f = ((int)(xmin/d)-1)*d; //while (f<xmin) // f += d; int n = 1+(int)((xmax-f)/d); _xmin = xmin; _xmax = xmax; _ntic = n; _dtic = d; _ftic = f; computeMultiple(); computeMinorTics(); }
protected void init(Cdouble[] poles, Cdouble[] zeros, double gain) { Check.argument(poles.length>0 || zeros.length>0, "at least one pole or zero is specified"); // Sort poles and zeros so that complex conjugate pairs are first. poles = sortPolesOrZeros(poles); zeros = sortPolesOrZeros(zeros); // Construct 2nd-order filters. int np = poles.length; int nz = zeros.length; _n1 = max((np+1)/2,(nz+1)/2); _f1 = new Recursive2ndOrderFilter[_n1]; gain = pow(gain,1.0/_n1); Cdouble c0 = new Cdouble(0.0,0.0); for (int i1=0,ip=0,iz=0; i1<_n1; ++i1) { Cdouble pole1 = (ip<np)?poles[ip++]:c0; Cdouble pole2 = (ip<np)?poles[ip++]:c0; Cdouble zero1 = (iz<nz)?zeros[iz++]:c0; Cdouble zero2 = (iz<nz)?zeros[iz++]:c0; _f1[i1] = new Recursive2ndOrderFilter(pole1,pole2,zero1,zero2,gain); } }
double xmax = _xmax = max(x1,x2); xmin -= (xmax-xmin)*FLT_EPSILON; xmax += (xmax-xmin)*FLT_EPSILON;
private void testMT( LineSearch.Function func, LineSearch ls, double[] se, double[] ge, int[] ne) { double s = 1.0e-3; for (int ie=0; ie<se.length; ++ie,s*=100.0) { double[] fg = func.evaluate(0.0); double f = fg[0]; double g = fg[1]; double smin = 0.0; double smax = 4.0*max(1.0,s); LineSearch.Result lsr = ls.search(s,f,g,smin,smax); trace("s0="+s); trace(" s="+lsr.s+" f'(s)="+lsr.g + " ended="+lsr.ended + " neval="+lsr.neval); assertTrue(lsr.converged()); assertEquals(se[ie],lsr.s,0.1*abs(se[ie])); //assertEquals(ge[ie],lsr.g,0.1*abs(ge[ie])); assertEquals(ne[ie],lsr.neval); } }