Java Code Examples for org.apache.commons.math3.complex.Complex#getReal()
The following examples show how to use
org.apache.commons.math3.complex.Complex#getReal() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Find a real root in the given interval. * * Despite the bracketing condition, the root returned by * {@link LaguerreSolver.ComplexSolver#solve(Complex[],Complex)} may * not be a real zero inside {@code [min, max]}. * For example, <code>p(x) = x<sup>3</sup> + 1,</code> * with {@code min = -2}, {@code max = 2}, {@code initial = 0}. * When it occurs, this code calls * {@link LaguerreSolver.ComplexSolver#solveAll(Complex[],Complex)} * in order to obtain all roots and picks up one real root. * * @param lo Lower bound of the search interval. * @param hi Higher bound of the search interval. * @param fLo Function value at the lower bound of the search interval. * @param fHi Function value at the higher bound of the search interval. * @return the point at which the function value is zero. * @deprecated This method should not be part of the public API: It will * be made private in version 4.0. */ @Deprecated public double laguerre(double lo, double hi, double fLo, double fHi) { final Complex c[] = ComplexUtils.convertToComplex(getCoefficients()); final Complex initial = new Complex(0.5 * (lo + hi), 0); final Complex z = complexSolver.solve(c, initial); if (complexSolver.isRoot(lo, hi, z)) { return z.getReal(); } else { double r = Double.NaN; // Solve all roots and select the one we are seeking. Complex[] root = complexSolver.solveAll(c, initial); for (int i = 0; i < root.length; i++) { if (complexSolver.isRoot(lo, hi, root[i])) { r = root[i].getReal(); break; } } return r; } }
Example 2
Source File: InterfacePowerLoadRandomChangeTrainCaseBuilder.java From DeepMachineLearning with Apache License 2.0 | 6 votes |
@Override public double[] getNetOutput() { int i = 3; double[] output = new double[2 * i]; Complex power = getAclfNet().getBranch("Bus5->Bus6(1)").powerFrom2To(); output[0] = power.getReal(); output[1] = power.getImaginary(); power = getAclfNet().getBranch("Bus4->Bus7(1)").powerFrom2To(); output[2] = power.getReal(); output[3] = power.getImaginary(); power = getAclfNet().getBranch("Bus4->Bus9(1)").powerFrom2To(); output[4] = power.getReal(); output[5] = power.getImaginary(); return output; }
Example 3
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Find a real root in the given interval. * * Despite the bracketing condition, the root returned by * {@link LaguerreSolver.ComplexSolver#solve(Complex[],Complex)} may * not be a real zero inside {@code [min, max]}. * For example, <code>p(x) = x<sup>3</sup> + 1,</code> * with {@code min = -2}, {@code max = 2}, {@code initial = 0}. * When it occurs, this code calls * {@link LaguerreSolver.ComplexSolver#solveAll(Complex[],Complex)} * in order to obtain all roots and picks up one real root. * * @param lo Lower bound of the search interval. * @param hi Higher bound of the search interval. * @param fLo Function value at the lower bound of the search interval. * @param fHi Function value at the higher bound of the search interval. * @return the point at which the function value is zero. * @deprecated This method should not be part of the public API: It will * be made private in version 4.0. */ @Deprecated public double laguerre(double lo, double hi, double fLo, double fHi) { final Complex c[] = ComplexUtils.convertToComplex(getCoefficients()); final Complex initial = new Complex(0.5 * (lo + hi), 0); final Complex z = complexSolver.solve(c, initial); if (complexSolver.isRoot(lo, hi, z)) { return z.getReal(); } else { double r = Double.NaN; // Solve all roots and select the one we are seeking. Complex[] root = complexSolver.solveAll(c, initial); for (int i = 0; i < root.length; i++) { if (complexSolver.isRoot(lo, hi, root[i])) { r = root[i].getReal(); break; } } return r; } }
Example 4
Source File: SV.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
public SV otherSide(double r, double x, double g1, double b1, double g2, double b2, double ratio) { Complex z = new Complex(r, x); // z=r+jx Complex y1 = new Complex(g1, b1); // y1=g1+jb1 Complex y2 = new Complex(g2, b2); // y2=g2+jb2 Complex s1 = new Complex(p, q); // s1=p1+jq1 Complex u1 = ComplexUtils.polar2Complex(u, Math.toRadians(a)); Complex v1 = u1.divide(Math.sqrt(3f)); // 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 i2p = i1p.subtract(y1.multiply(v1p)); // i2p=i1p-y1*v1p Complex v2 = v1p.subtract(z.multiply(i2p)); // v2p=v1p-z*i2 Complex i2 = i2p.subtract(y2.multiply(v2)); // i2=i2p-y2*v2 Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2) Complex u2 = v2.multiply(Math.sqrt(3f)); return new SV(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument())); }
Example 5
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Find a real root in the given interval. * * Despite the bracketing condition, the root returned by * {@link LaguerreSolver.ComplexSolver#solve(Complex[],Complex)} may * not be a real zero inside {@code [min, max]}. * For example, <code>p(x) = x<sup>3</sup> + 1,</code> * with {@code min = -2}, {@code max = 2}, {@code initial = 0}. * When it occurs, this code calls * {@link LaguerreSolver.ComplexSolver#solveAll(Complex[],Complex)} * in order to obtain all roots and picks up one real root. * * @param lo Lower bound of the search interval. * @param hi Higher bound of the search interval. * @param fLo Function value at the lower bound of the search interval. * @param fHi Function value at the higher bound of the search interval. * @return the point at which the function value is zero. * @deprecated This method should not be part of the public API: It will * be made private in version 4.0. */ @Deprecated public double laguerre(double lo, double hi, double fLo, double fHi) { final Complex c[] = ComplexUtils.convertToComplex(getCoefficients()); final Complex initial = new Complex(0.5 * (lo + hi), 0); final Complex z = complexSolver.solve(c, initial); if (complexSolver.isRoot(lo, hi, z)) { return z.getReal(); } else { double r = Double.NaN; // Solve all roots and select the one we are seeking. Complex[] root = complexSolver.solveAll(c, initial); for (int i = 0; i < root.length; i++) { if (complexSolver.isRoot(lo, hi, root[i])) { r = root[i].getReal(); break; } } return r; } }
Example 6
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Find a real root in the given interval. * * Despite the bracketing condition, the root returned by * {@link LaguerreSolver.ComplexSolver#solve(Complex[],Complex)} may * not be a real zero inside {@code [min, max]}. * For example, <code>p(x) = x<sup>3</sup> + 1,</code> * with {@code min = -2}, {@code max = 2}, {@code initial = 0}. * When it occurs, this code calls * {@link LaguerreSolver.ComplexSolver#solveAll(Complex[],Complex)} * in order to obtain all roots and picks up one real root. * * @param lo Lower bound of the search interval. * @param hi Higher bound of the search interval. * @param fLo Function value at the lower bound of the search interval. * @param fHi Function value at the higher bound of the search interval. * @return the point at which the function value is zero. * @deprecated This method should not be part of the public API: It will * be made private in version 4.0. */ @Deprecated public double laguerre(double lo, double hi, double fLo, double fHi) { final Complex c[] = ComplexUtils.convertToComplex(getCoefficients()); final Complex initial = new Complex(0.5 * (lo + hi), 0); final Complex z = complexSolver.solve(c, initial); if (complexSolver.isRoot(lo, hi, z)) { return z.getReal(); } else { double r = Double.NaN; // Solve all roots and select the one we are seeking. Complex[] root = complexSolver.solveAll(c, initial); for (int i = 0; i < root.length; i++) { if (complexSolver.isRoot(lo, hi, root[i])) { r = root[i].getReal(); break; } } return r; } }
Example 7
Source File: Biquad.java From chart-fx with Apache License 2.0 | 5 votes |
public void setOnePole(final Complex pole, final Complex zero) { final double a0 = 1; final double a1 = -pole.getReal(); final double a2 = 0; final double b0 = -zero.getReal(); final double b1 = 1; final double b2 = 0; setCoefficients(a0, a1, a2, b0, b1, b2); }
Example 8
Source File: TransformerModel.java From ipst with Mozilla Public License 2.0 | 5 votes |
public StateVariable toSv1(StateVariable sv2) { Complex s2 = new Complex(-sv2.p, -sv2.q); // s2=p2+jq2 Complex u2 = ComplexUtils.polar2Complex(sv2.u, Math.toRadians(sv2.theta)); Complex v2 = u2.divide(SQUARE_3); // v2=u2/sqrt(3) Complex i2 = s2.divide(v2.multiply(3)).conjugate(); // i2=conj(s2/(3*v2)) Complex v1p = v2.add(z.multiply(i2)); // v1'=v2+z*i2 Complex i1p = i2.negate().add(y.multiply(v1p)); // i1'=-i2+v1'*y Complex i1 = i1p.multiply(ratio); // i1=i1p*ration Complex v1 = v1p.divide(ratio); // v1=v1p/ration Complex s1 = v1.multiply(3).multiply(i1.conjugate()); // s1=3*v1*conj(i1) Complex u1 = v1.multiply(SQUARE_3); return new StateVariable(-s1.getReal(), -s1.getImaginary(), u1.abs(), Math.toDegrees(u1.getArgument())); }
Example 9
Source File: TransformerModel.java From ipst with Mozilla Public License 2.0 | 5 votes |
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())); }
Example 10
Source File: Biquad.java From iirj with Apache License 2.0 | 5 votes |
public void setTwoPole(Complex pole1, Complex zero1, Complex pole2, Complex zero2) { double a0 = 1; double a1; double a2; if (pole1.getImaginary() != 0) { a1 = -2 * pole1.getReal(); a2 = pole1.abs() * pole1.abs(); } else { a1 = -(pole1.getReal() + pole2.getReal()); a2 = pole1.getReal() * pole2.getReal(); } double b0 = 1; double b1; double b2; if (zero1.getImaginary() != 0) { b1 = -2 * zero1.getReal(); b2 = zero1.abs() * zero1.abs(); } else { b1 = -(zero1.getReal() + zero2.getReal()); b2 = zero1.getReal() * zero2.getReal(); } setCoefficients(a0, a1, a2, b0, b1, b2); }
Example 11
Source File: Biquad.java From iirj with Apache License 2.0 | 5 votes |
public void setOnePole(Complex pole, Complex zero) { double a0 = 1; double a1 = -pole.getReal(); double a2 = 0; double b0 = -zero.getReal(); double b1 = 1; double b2 = 0; setCoefficients(a0, a1, a2, b0, b1, b2); }
Example 12
Source File: Operations.java From january with Eclipse Public License 1.0 | 5 votes |
@Override public void complexOperate(double[] out, double ra, double ia, double rb, double ib) { Complex c = new Complex(ra, ia); c = ib == 0 ? c.pow(rb) : c.pow(new Complex(rb, ib)); out[0] = c.getReal(); out[1] = c.getImaginary(); }
Example 13
Source File: Operations.java From january with Eclipse Public License 1.0 | 4 votes |
/** * @param z * given value as Complex */ public UseIfEqualTo(Complex z) { super(z.getReal()); di = z.getImaginary(); }
Example 14
Source File: MathSupplement.java From iirj with Apache License 2.0 | 4 votes |
public static Complex adjust_imag(Complex c) { if (Math.abs(c.getImaginary()) < 1e-30) return new Complex(c.getReal(), 0); else return c; }
Example 15
Source File: MathSupplement.java From iirj with Apache License 2.0 | 4 votes |
public static Complex addmul(Complex c, double v, Complex c1) { return new Complex(c.getReal() + v * c1.getReal(), c.getImaginary() + v * c1.getImaginary()); }
Example 16
Source File: MathSupplement.java From iirj with Apache License 2.0 | 4 votes |
public static Complex recip(Complex c) { double n = 1.0 / (c.abs() * c.abs()); return new Complex(n * c.getReal(), n * c.getImaginary()); }
Example 17
Source File: TransformUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Builds a new two dimensional array of {@code double} filled with the real * and imaginary parts of the specified {@link Complex} numbers. In the * returned array {@code dataRI}, the data is laid out as follows * <ul> * <li>{@code dataRI[0][i] = dataC[i].getReal()},</li> * <li>{@code dataRI[1][i] = dataC[i].getImaginary()}.</li> * </ul> * * @param dataC the array of {@link Complex} data to be transformed * @return a two dimensional array filled with the real and imaginary parts * of the specified complex input */ public static double[][] createRealImaginaryArray(final Complex[] dataC) { final double[][] dataRI = new double[2][dataC.length]; final double[] dataR = dataRI[0]; final double[] dataI = dataRI[1]; for (int i = 0; i < dataC.length; i++) { final Complex c = dataC[i]; dataR[i] = c.getReal(); dataI[i] = c.getImaginary(); } return dataRI; }
Example 18
Source File: TransformUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Builds a new two dimensional array of {@code double} filled with the real * and imaginary parts of the specified {@link Complex} numbers. In the * returned array {@code dataRI}, the data is laid out as follows * <ul> * <li>{@code dataRI[0][i] = dataC[i].getReal()},</li> * <li>{@code dataRI[1][i] = dataC[i].getImaginary()}.</li> * </ul> * * @param dataC the array of {@link Complex} data to be transformed * @return a two dimensional array filled with the real and imaginary parts * of the specified complex input */ public static double[][] createRealImaginaryArray(final Complex[] dataC) { final double[][] dataRI = new double[2][dataC.length]; final double[] dataR = dataRI[0]; final double[] dataI = dataRI[1]; for (int i = 0; i < dataC.length; i++) { final Complex c = dataC[i]; dataR[i] = c.getReal(); dataI[i] = c.getImaginary(); } return dataRI; }
Example 19
Source File: TransformUtils.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Builds a new two dimensional array of {@code double} filled with the real * and imaginary parts of the specified {@link Complex} numbers. In the * returned array {@code dataRI}, the data is laid out as follows * <ul> * <li>{@code dataRI[0][i] = dataC[i].getReal()},</li> * <li>{@code dataRI[1][i] = dataC[i].getImaginary()}.</li> * </ul> * * @param dataC the array of {@link Complex} data to be transformed * @return a two dimensional array filled with the real and imaginary parts * of the specified complex input */ public static double[][] createRealImaginaryArray(final Complex[] dataC) { final double[][] dataRI = new double[2][dataC.length]; final double[] dataR = dataRI[0]; final double[] dataI = dataRI[1]; for (int i = 0; i < dataC.length; i++) { final Complex c = dataC[i]; dataR[i] = c.getReal(); dataI[i] = c.getImaginary(); } return dataRI; }
Example 20
Source File: AclfTrainDataGenerator.java From DeepMachineLearning with Apache License 2.0 | 2 votes |
/** * compute and return the mismatch based on the network solution * for bus voltage * * @param netVolt network bus voltage solution * @return mismatch info string */ public double[] getMismatch(double[] netVolt) { Complex maxMis= this.trainCaseBuilder.calMismatch(netVolt).maxMis; return new double[] {maxMis.getReal(),maxMis.getImaginary()}; }