Refine search
/** * Check whether the given complex root is actually a real zero * in the given interval, within the solver tolerance level. * * @param min Lower bound for the interval. * @param max Upper bound for the interval. * @param z Complex root. * @return {@code true} if z is a real zero. */ public boolean isRoot(double min, double max, Complex z) { if (isSequence(min, z.getReal(), max)) { double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); return (FastMath.abs(z.getImaginary()) <= tolerance) || (z.abs() <= getFunctionValueAccuracy()); } return false; }
final Complex nC = new Complex(n, 0); final Complex n1C = new Complex(n - 1, 0); Complex oldz = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); while (true) { Complex d2v = Complex.ZERO; for (int j = n-1; j >= 0; j--) { d2v = dv.add(z.multiply(d2v)); dv = pv.add(z.multiply(dv)); pv = coefficients[j].add(z.multiply(pv)); d2v = d2v.multiply(new Complex(2.0, 0.0)); final double tolerance = FastMath.max(relativeAccuracy * z.abs(), absoluteAccuracy); if ((z.subtract(oldz)).abs() <= tolerance) { return z; if (pv.abs() <= functionValueAccuracy) { return z; final Complex G = dv.divide(pv); final Complex G2 = G.multiply(G); final Complex H = G2.subtract(d2v.divide(pv)); final Complex delta = n1C.multiply((nC.multiply(H)).subtract(G2)); final Complex deltaSqrt = delta.sqrt();
/** * Compute the * <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top"> * inverse sine</a> of this complex number. * Implements the formula: * <p> * {@code asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz))} * </p><p> * Returns {@link Complex#NaN} if either real or imaginary part of the * input argument is {@code NaN} or infinite.</p> * * @return the inverse sine of this complex number. * @since 1.2 */ public Complex asin() { if (isNaN) { return NaN; } return sqrt1z().add(this.multiply(I)).log().multiply(I.negate()); }
/** * Multiply every component in the given complex array by the * given real number. The change is made in place. * * @param f the complex array to be scaled * @param d the real scaling coefficient * @return a reference to the scaled array */ public static Complex[] scaleArray(Complex[] f, double d) { for (int i = 0; i < f.length; i++) { f[i] = new Complex(d * f[i].getReal(), d * f[i].getImaginary()); } return f; }
/** * Performs a division of two complex numbers. * * @param xr real part of the first number * @param xi imaginary part of the first number * @param yr real part of the second number * @param yi imaginary part of the second number * @return result of the complex division */ private Complex cdiv(final double xr, final double xi, final double yr, final double yi) { return new Complex(xr, xi).divide(new Complex(yr, yi)); }
public StateVariable toSv2(StateVariable sv1) { Complex s1 = new Complex(-sv1.p, -sv1.q); // s1=p1+jq1 Complex u1 = ComplexUtils.polar2Complex(sv1.u, Math.toRadians(sv1.theta)); Complex v1 = u1.divide(SQUARE_3); // v1=u1/sqrt(3) Complex v1p = v1.multiply(ratio); // v1p=v1*rho Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1)) Complex i1p = i1.divide(ratio); // i1p=i1/rho Complex i2 = i1p.subtract(y.multiply(v1p)).negate(); // i2=-(i1p-y*v1p) Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2 Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2) Complex u2 = v2.multiply(SQUARE_3); return new StateVariable(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument())); }
return result; if (isInfinite()) { result.add(INF); return result; final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n); final double nthPhi = getArgument() / n; final double slice = 2 * FastMath.PI / n; double innerPart = nthPhi; for (int k = 0; k < n ; k++) { final double realPart = nthRootOfAbs * FastMath.cos(innerPart); final double imaginaryPart = nthRootOfAbs * FastMath.sin(innerPart); result.add(createComplex(realPart, imaginaryPart)); innerPart += slice;
for (int j = FastMath.max(i - 1, 0); j < n; j++) { norm += FastMath.abs(matrixT[i][j]); final Complex result = cdiv(0.0, -matrixT[idx - 1][idx], matrixT[idx - 1][idx - 1] - p, q); matrixT[idx - 1][idx - 1] = result.getReal(); matrixT[idx - 1][idx] = result.getImaginary(); if (Precision.equals(imagEigenvalues[i], 0.0)) { final Complex c = cdiv(-ra, -sa, w, q); matrixT[i][idx - 1] = c.getReal(); matrixT[i][idx] = c.getImaginary(); } else { matrixT[i][idx - 1] = c.getReal(); matrixT[i][idx] = c.getImaginary(); if (FastMath.abs(x) > (FastMath.abs(z) + FastMath.abs(q))) { final Complex c2 = cdiv(-r - y * matrixT[i][idx - 1], -s - y * matrixT[i][idx], z, q); matrixT[i + 1][idx - 1] = c2.getReal(); matrixT[i + 1][idx] = c2.getImaginary();
zhp[i] = (bw / 2) / z[i]; Complex numerator = new Complex((bw/2)); for(int i = 0; i < p.length; i++) php[i] = numerator.divide(p[i]); zbs[i] = new Complex(0, wo); for(int i = 0; i < degree; i++) zbs[degree + i] = new Complex(0, -wo); for(int i = 0; i < p.length; i++) pbs[i] = php[i].add((php[i].pow(2).subtract(Math.pow(wo, 2))).sqrt()); for(int i = 0; i < p.length; i++) pbs[i + p.length] = php[i].subtract((php[i].pow(2).subtract(Math.pow(wo, 2))).sqrt()); Complex temp = new Complex(1,0); for (Complex aP : p) temp = temp.multiply(aP.negate()); pProd = temp.getReal(); kbs = (int) (k / pProd); return new ArrayList<Object>(Arrays.asList(zbs, pbs, kbs));
/** * Return the ceiling value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber ceil(IComplexNumber num) { Complex c = new Complex(FastMath.ceil(num.realComponent().doubleValue()), FastMath.ceil(num.imaginaryComponent().doubleValue())); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }
/** * Return the floor value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber floor(IComplexNumber num) { Complex c = new Complex(FastMath.floor(num.realComponent().doubleValue()), FastMath.floor(num.imaginaryComponent().doubleValue())); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }
/** * Raise a complex number to a power * * @param num the number to raise * @param power the power to raise to * @return the number raised to a power */ public static IComplexNumber pow(IComplexNumber num, double power) { Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).pow(power); if (c.isNaN()) c = new Complex(Nd4j.EPS_THRESHOLD, 0.0); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }
/** * Return the log value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber neg(IComplexNumber num) { Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).negate(); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }
for (int i = 1; i < (n >> 1); i++) { final double a = 0.5 * (f[i] + f[n - i]); final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n - i]); final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n - i]); x[i] = a - b; x[n - i] = a + b; transformed[0] = y[0].getReal(); transformed[1] = t1; for (int i = 1; i < (n >> 1); i++) { transformed[2 * i] = y[i].getReal(); transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary(); transformed[n] = y[n >> 1].getReal();
return createComplex(0.0, 0.0); double t = FastMath.sqrt((FastMath.abs(real) + abs()) / 2.0); if (real >= 0.0) { return createComplex(t, imaginary / (2.0 * t)); } else { return createComplex(FastMath.abs(imaginary) / (2.0 * t), FastMath.copySign(1d, imaginary) * t);
relativeDegree(z, p); double fs2 = 2 * fs; Complex complexFs2 = new Complex(fs2); for(int i = 0; i < z.length; i++){ zz[i] = (complexFs2.add(z[i])).divide(complexFs2.subtract(z[i])); pz[i] = (complexFs2.add(p[i])).divide(complexFs2.subtract(p[i])); if (!pz2.contains(aPz) && !pz2.contains(aPz.conjugate())) { pz2.add(aPz); pz2.add(pz2.get(i).conjugate()); Complex temp = new Complex(1,0); for (Complex aZ : z) temp = temp.multiply(complexFs2.subtract(aZ)); Complex temp2 = new Complex(1,0); for (Complex aP : p) temp2 = temp2.multiply(complexFs2.subtract(aP)); kz = (k * (temp.divide(temp2)).getReal()); return new ArrayList<Object>(Arrays.asList(zz, pzRearranged, kz));
/** * Return the tanh of a complex number * * @param num the tanh of a complex number * @return the tanh of a complex number */ public static IComplexNumber hardTanh(IComplexNumber num) { Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).tanh(); if (c.getReal() < -1.0) c = new Complex(-1.0, c.getImaginary()); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }
/** * Return the absolute value of the given complex number * * @param num the number to getScalar the absolute value for * @return the absolute value of this complex number */ public static IComplexNumber sqrt(IComplexNumber num) { Complex c = new Complex(num.realComponent().doubleValue(), num.imaginaryComponent().doubleValue()).sqrt(); return Nd4j.createDouble(c.getReal(), c.getImaginary()); }