private KaiserWindow(double error, double width, double length) { _error = error; _width = width; _length = length; double a = -20.0*log10(_error); if (a<=21.0) { _alpha = 0.0; } else if (a<=50.0) { _alpha = 0.5842*pow(a-21.0,0.4)+0.07886*(a-21.0); } else { _alpha = 0.1102*(a-8.7); } _scale = 1.0/ino(_alpha); _xxmax = 0.25*_length*_length; }
private static float[] generate(int n) { Random r = new Random(); float[] c = new float[n*3]; float x,y,z; for (int i=0; i<n; ++i) { x = (float)cos(2* MathPlus.PI*i); y = i*10; z = r.nextFloat() * 100; c[3*i ] = x; c[3*i+1] = y; c[3*i+2] = z; } return c; }
public void test() { assertEquals(0.0f,sin(FLT_PI)); assertEquals(0.0d,sin(DBL_PI)); assertEquals(1.0f,cos(2.0f*FLT_PI)); assertEquals(1.0d,cos(2.0d*DBL_PI)); assertEquals(1.0f,tan(FLT_PI/4.0f)); assertEquals(1.0d,tan(DBL_PI/4.0d)); assertEquals(FLT_PI/2.0f,asin(1.0f)); assertEquals(DBL_PI/2.0d,asin(1.0d)); assertEquals(FLT_PI/2.0f,acos(0.0f)); assertEquals(DBL_PI/2.0d,acos(0.0d)); assertEquals(FLT_PI/4.0f,atan(1.0f)); assertEquals(DBL_PI/4.0d,atan(1.0d)); assertEquals(FLT_PI/2.0f,atan2(1.0f,0.0f)); assertEquals(DBL_PI/2.0d,atan2(1.0d,0.0d)); assertEquals(-3.0f*FLT_PI/4.0f,atan2(-1.0f,-1.0f)); assertEquals(-3.0d*DBL_PI/4.0d,atan2(-1.0d,-1.0d)); assertEquals(FLT_PI,toRadians(180.0f)); assertEquals(DBL_PI,toRadians(180.0d)); assertEquals(180.0f,toDegrees(FLT_PI)); assertEquals(180.0d,toDegrees(DBL_PI));
double xmin = _xmin = min(x1,x2); double xmax = _xmax = max(x1,x2); xmin -= (xmax-xmin)*FLT_EPSILON; xmax += (xmax-xmin)*FLT_EPSILON; for (int imult=0; imult<nmult; ++imult) { int m = _mult[imult]; int l = (int)floor(log10(dmax/m)); double d = m*pow(10.0,l); double f = ceil(xmin/d)*d; int n = 1+(int)((xmax-f)/d); if (n>nmax) { d *= 10; f = ceil(xmin/d)*d; n = 1+(int)((xmax-f)/d);
double wl = 2.0*DBL_PI*fl; double wh = 2.0*DBL_PI*fh; double xl = 2.0*tan(wl/2.0); double xh = 2.0*tan(wh/2.0); double pl = al*al; double ph = ah*ah; if (al>=ah) { int np = (int)ceil(0.5*log((pl*(1-ph))/(ph*(1-pl)))/log(xh/xl)); double xc = xl*pow(pl/(1-pl),0.5/np); double wc = 2.0*atan(xc/2.0); double fc = 0.5*wc/DBL_PI; makePolesZerosGain(fc,np,Type.LOW_PASS); } else { int np = (int)ceil(0.5*log((ph*(1-pl))/(pl*(1-ph)))/log(xh/xl)); double xc = xh*pow((1-ph)/ph,0.5/np); double wc = 2.0*atan(xc/2.0); double fc = 0.5*wc/DBL_PI; makePolesZerosGain(fc,np,Type.HIGH_PASS);
/** * 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(); }
final double sgng = gp * (ga / abs(ga)); double spf = sp; final double s = max(abs(theta), abs(ga), abs(gp)); double gamma = s * sqrt((theta / s) * (theta / s) - (ga / s) * (gp / s)); if (sp < sa) { gamma = -gamma; final double spc = sa + r * (sp - sa); final double spq = sa + ((ga / ((fa - fp) / (sp - sa) + ga)) / 2.0) * (sp - sa); if (abs(spc - sa) < abs(spq - sa)) { spf = spc; } else { final double s = max(abs(theta), abs(ga), abs(gp)); double gamma = s * sqrt((theta / s) * (theta / s) - (ga / s) * (gp / s)); if (sp > sa) { gamma = -gamma; final double spc = sp + r * (sa - sp); final double spq = sp + (gp / (gp - ga)) * (sa - sp); if (abs(spc - sp) > abs(spq - sp)) { spf = spc; } else { else if (abs(gp) < abs(ga)) { final double s = max(abs(theta), abs(ga), abs(gp));
private void computeMinorTics() { // the position out of 9 that the first tic should be before the first Major tic // e.g. 7 out of 9 double c = pow(10.0,(_expMin-ceil(_expMin)+1)); // the number of log-spaced tics that the last value is ahead of the // previous-to-first major tic int c2 = 9-(int)floor(c); // the number of log-spaced tics that the last value is behind the // next-after-last major tic double d = pow(10.0,(_expMax-floor(_expMax))); // the number of log-spaced tics that the last value is ahead of the last // major tic int d2 = (int)floor(d); _nticMinor = 9*(_ntic-1)+c2+d2; _dticMinor = 1; _fticMinor = pow(10,ceil(_expMin)-1)*(int)ceil(c); _ktic = c2+1; }
if (signum(v1a-v0a)!=signum(v1b-v0b)) { u0b = 1.0-p._u1; u1b = 1.0-p._u0; double vmin = min(min(v0a,v1a),min(v0b,v1b)); double vmax = max(max(v0a,v1a),max(v0b,v1b)); _v0 = (v0a<v1a)?vmin:vmax; _v1 = (v0a<v1a)?vmax:vmin; _u0 = u0; _u1 = u1; u0 = max((u0a-r0a*_u1)/(1.0-r0a),(u0b-r0b*_u1)/(1.0-r0b)); u1 = min((u1a-(1.0-r1a)*_u0)/r1a,(u1b-(1.0-r1b)*_u0)/r1b); ++niter; } while ((_u0<u0 || u1<_u1) && niter<10);
public double[] evaluate(double s) { int nwig = 39; double f,g; if (s<1.0-beta3) { f = 1.0-s; g = -1.0; } else if (s<1.0+beta3) { f = (s-1.0)*(s-1.0)/(2.0*beta3)+beta3/2.0; g = (s-1.0)/beta3; } else { f = s-1.0; g = 1.0; } double t1 = 2.0*nwig*atan(1.0); double t2 = (1.0-beta3)/t1; f += t2*sin(t1*s); g += (1.0-beta3)*cos(t1*s); return new double[]{f,g}; } private double beta3 = 1.0e-2;
} else if (s == smin && (f > ftest || g >= gtest)) { ended = SMIN; } else if (f <= ftest && abs(g) <= _gtol * (-ginit)) { ended = CONVERGED; if (abs(sb - sa) >= 0.66 * widthOld) { s = sa + 0.5 * (sb - sa); width = abs(sb - sa); slo = min(sa, sb); shi = max(sa, sb); } else { slo = s + SLO_FACTOR * (s - sa); s = max(s, smin); s = min(s, smax);
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, double ymax, double zmax) _xmin = max(xmin,_sx.getFirst()); _ymin = max(ymin,_sy.getFirst()); _zmin = max(zmin,_sz.getFirst()); _xmax = min(xmax,_sx.getLast()); _ymax = min(ymax,_sy.getLast()); _zmax = min(zmax,_sz.getLast()); int kxmin = _sx.indexOfNearest(_xmin); int kymin = _sy.indexOfNearest(_ymin); int jsmax = max(0,_ksmax-1)/(_ls-1); int jtmax = max(0,_ktmax-1)/(_lt-1);
xm = 0.5*(a+b), tol1 = EPS*abs(x)+tol/3.0, tol2 = 2.0*tol1; abs(x-xm) > tol2-0.5*(b-a); xm = 0.5*(a+b), tol1 = EPS*abs(x)+tol/3.0, tol2 = 2.0*tol1) { boolean gsstep = abs(e)<=tol1; if (q>0.0) p = -p; q = abs(q); r = e; e = d; if (abs(p)<abs(0.5*q*r) && p>q*(a-x) && p<q*(b-x)) { d = p/q; double u = x+d; double u = x+(abs(d)>=tol1?d:d>=0.0?tol1:-tol1); double fu = f(u);