Java Code Examples for org.apache.commons.math3.complex.Complex#getImaginary()
The following examples show how to use
org.apache.commons.math3.complex.Complex#getImaginary() .
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: FinQuestionValidator.java From sakai with Educational Community License v2.0 | 6 votes |
static boolean isComplexNumber(String value) { boolean isComplex = true; Complex complex=null; try { DecimalFormat df = (DecimalFormat)NumberFormat.getNumberInstance(Locale.US); df.setGroupingUsed(false); // Numerical format ###.## (decimal symbol is the point) ComplexFormat complexFormat = new ComplexFormat(df); complex = complexFormat.parse(value); // Only checks for complex numbers, not real numbers if (complex.getImaginary() == 0) { isComplex = false; } } catch (Exception e) { isComplex = false; } return isComplex; }
Example 2
Source File: FinQuestionValidator.java From sakai with Educational Community License v2.0 | 6 votes |
static boolean isComplexNumber(String value) { boolean isComplex = true; Complex complex=null; try { DecimalFormat df = (DecimalFormat)NumberFormat.getNumberInstance(Locale.US); df.setGroupingUsed(false); // Numerical format ###.## (decimal symbol is the point) ComplexFormat complexFormat = new ComplexFormat(df); complex = complexFormat.parse(value); // Only checks for complex numbers, not real numbers if (complex.getImaginary() == 0) { isComplex = false; } } catch (Exception e) { isComplex = false; } return isComplex; }
Example 3
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 4
Source File: ACLineSegmentConversion.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
public PiModel toPiModel() { PiModel pi = new PiModel(); // Y2 = (A - 1)/B // Y1 = (D - 1)/B Complex y1 = d.add(-1).divide(b); Complex y2 = a.add(-1).divide(b); pi.r = b.getReal(); pi.x = b.getImaginary(); pi.g1 = y1.getReal(); pi.b1 = y1.getImaginary(); pi.g2 = y2.getReal(); pi.b2 = y2.getImaginary(); return pi; }
Example 5
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 6
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 7
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 8
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 9
Source File: ContinuousWavelet.java From chart-fx with Apache License 2.0 | 5 votes |
/** * @param data input data * @param nQuantx number of bins on the time axis * @param nQuanty number of frequency bins of full range * @param nu Morlet wavelet oscillation parameter * @param fmin minimum scalogram frequency range * @param fmax maximum scalogram frequency range * @return Scalogram power in dB */ public synchronized double[][] getScalogramArray(final double[] data, final int nQuantx, final int nQuanty, final double nu, final double fmin, final double fmax) { final int nQuantyInternal = (int) Math.floor(nQuanty * (fmax - fmin) / 0.5) + 1; final double[][] ret = new double[nQuantx][nQuantyInternal]; fstatus = 0; for (int i = 0; i < nQuantx; i++) { final double t = data.length / nQuantx * i; // update status variable fstatus = (int) ((double) i / (double) nQuantx * 100); final int min = (int) (2 * fmin * nQuanty); final int max = (int) (2 * fmax * nQuanty); for (int j = min; j < max; j++) { final double f = 0.5 * j / nQuanty; if (f != 0) { final double scale = nu / f; final Complex val = WaveletTransform(data, scale, t, nu); final double power = val.getReal() * val.getReal() + val.getImaginary() * val.getImaginary(); ret[i][j - min] = 10 * TMathConstants.Log10(power + 1e-99); } else { ret[i][j - min] = Double.NaN; } } } fstatus = 100; return ret; }
Example 10
Source File: CalculatedValue.java From microMathematics with GNU General Public License v3.0 | 5 votes |
public ValueType setComplexValue(Complex c) { real = c.getReal(); imaginary = c.getImaginary(); valueType = (imaginary != 0.0) ? ValueType.COMPLEX : ValueType.REAL; return valueType; }
Example 11
Source File: DFT.java From AILibs with GNU Affero General Public License v3.0 | 4 votes |
@Override public void fit(final double[] input) { if (this.numberOfDisieredCoefficients > input.length) { throw new IllegalArgumentException("There cannot be more DFT coefficents calcualated than there entrys in the basis instance."); } if (input.length == 0) { throw new IllegalArgumentException("The to transform instance can not be of length zero."); } if (this.rekursivFirstInstance) { this.startingpoint = 0; } // The buffer for the calculated DFT coefficeients this.dftCoefficientsInstance = new double[this.numberOfDisieredCoefficients * 2 - (this.startingpoint * 2)]; // Variable used to make steps of size two in a loop that makes setps of size one int loopcounter = 0; for (int coefficient = this.startingpoint; coefficient < this.numberOfDisieredCoefficients; coefficient++) { Complex result = new Complex(0.0, 0.0); for (int entry = 0; entry < input.length; entry++) { // calculates the real and imaginary part of the entry according to the desired coefficient // c.f. p. 1510 "The BOSS is concerned with time series classification in the presence of noise" by Patrick Sch�fer double realpart = Math.cos(-(1.0 / input.length) * 2.0 * Math.PI * entry * coefficient); double imaginarypart = Math.sin(-(1.0 / input.length) * 2.0 * Math.PI * entry * coefficient); Complex tmp = new Complex(realpart, imaginarypart); tmp = tmp.multiply(input[entry]); result = result.add(tmp); } // saves the calculated coefficient in the buffer with first the real part and than the imaginary this.dftCoefficientsInstance[loopcounter] = result.getReal(); this.dftCoefficientsInstance[loopcounter + 1] = result.getImaginary(); loopcounter += 2; } if (this.rekursivFirstInstance && this.meanCorrected) { this.startingpoint = 1; } this.fittedInstance = true; }
Example 12
Source File: FileReader.java From microMathematics with GNU General Public License v3.0 | 4 votes |
CalculatedValue.ValueType getFileElement(CalculatedValue outValue) { if (rootFormula instanceof Equation) { Equation eq = (Equation) rootFormula; final int argNumber = eq.getArguments() != null ? eq.getArguments().size() : 0; String strValue = null; if (argNumber == 1 || argNumber == 2) { final int a0 = eq.getArgumentValue(0).getInteger(); if (a0 < fileBuffer.size()) { final ArrayList<String> line = fileBuffer.get(a0); final int a1 = (argNumber == 1) ? 0 : eq.getArgumentValue(1).getInteger(); if (a1 < line.size()) { strValue = line.get(a1); } } } if (strValue != null) { try { return outValue.setValue(Double.parseDouble(strValue)); } catch (Exception ex) { // nothing to do: we will try to convert it to complex } Complex cmplValue = TermParser.complexValueOf(strValue); if (cmplValue != null) { if (cmplValue.getImaginary() != 0.0) { return outValue.setComplexValue(cmplValue.getReal(), cmplValue.getImaginary()); } else { return outValue.setValue(cmplValue.getReal()); } } } return outValue.invalidate(CalculatedValue.ErrorType.NOT_A_NUMBER); } return outValue.invalidate(CalculatedValue.ErrorType.TERM_NOT_READY); }
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 recip(Complex c) { double n = 1.0 / (c.abs() * c.abs()); return new Complex(n * c.getReal(), n * c.getImaginary()); }
Example 15
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 16
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 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()}; }