Java Code Examples for org.apache.commons.math3.complex.Complex#abs()
The following examples show how to use
org.apache.commons.math3.complex.Complex#abs() .
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: LightfieldZernike.java From cineast with MIT License | 6 votes |
/** * Extracts the Lightfield Fourier descriptors from a provided BufferedImage. The returned list contains * elements for each identified contour of adequate size. * * @param image Image for which to extract the Lightfield Fourier descriptors. * @param poseidx Poseidx of the extracted image. * @return List of descriptors for image. */ @Override protected List<float[]> featureVectorsFromImage(BufferedImage image, int poseidx) { final List<ZernikeMoments> moments = ZernikeHelper.zernikeMomentsForShapes(image, RENDERING_SIZE /2, 10); final List<float[]> features = new ArrayList<>(moments.size()); for (ZernikeMoments moment : moments) { float[] feature = new float[SIZE]; int i = 0; for (Complex m : moment.getMoments()) { feature[i] = (float)m.abs(); i++; } feature = MathHelper.normalizeL2InPlace(feature); feature[0] = poseidx; features.add(feature); } return features; }
Example 2
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 3
Source File: Biquad.java From chart-fx with Apache License 2.0 | 5 votes |
public void setTwoPole(final Complex pole1, final Complex zero1, final Complex pole2, final Complex zero2) { final double a0 = 1; double a1; double a2; if (pole1.getImaginary() == 0) { a1 = -(pole1.getReal() + pole2.getReal()); a2 = pole1.getReal() * pole2.getReal(); } else { a1 = -2 * pole1.getReal(); a2 = pole1.abs() * pole1.abs(); } final double b0 = 1; double b1; double b2; if (zero1.getImaginary() == 0) { b1 = -(zero1.getReal() + zero2.getReal()); b2 = zero1.getReal() * zero2.getReal(); } else { b1 = -2 * zero1.getReal(); b2 = zero1.abs() * zero1.abs(); } setCoefficients(a0, a1, a2, b0, b1, b2); }
Example 4
Source File: FFTView.java From Android-Audio-Recorder with Apache License 2.0 | 5 votes |
public static double[] fft(short[] buffer, int offset, int len) { int len2 = (int) Math.pow(2, Math.ceil(Math.log(len) / Math.log(2))); final double[][] dataRI = new double[][]{ new double[len2], new double[len2] }; double[] dataR = dataRI[0]; double[] dataI = dataRI[1]; double powerInput = 0; for (int i = 0; i < len; i++) { dataR[i] = buffer[offset + i] / (float) 0x7fff; powerInput += dataR[i] * dataR[i]; } powerInput = Math.sqrt(powerInput / len); FastFourierTransformer.transformInPlace(dataRI, DftNormalization.STANDARD, TransformType.FORWARD); double[] data = new double[len2 / 2]; data[0] = 10 * Math.log10(Math.pow(new Complex(dataR[0], dataI[0]).abs() / len2, 2)); double powerOutput = 0; for (int i = 1; i < data.length; i++) { Complex c = new Complex(dataR[i], dataI[i]); double p = c.abs(); p = p / len2; p = p * p; p = p * 2; double dB = 10 * Math.log10(p); powerOutput += p; data[i] = dB; } powerOutput = Math.sqrt(powerOutput); // if(powerInput != powerOutput) { // throw new RuntimeException("in " + powerInput + " out " + powerOutput); // } return data; }
Example 5
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 6
Source File: FFT.java From cineast with MIT License | 5 votes |
/** * Returns true if the FFT only contains zeros and false * otherwise */ public final boolean isZero() { for (Complex coefficient : this.data) { if (coefficient.abs() > 0) { return false; } } return true; }
Example 7
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 8
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 9
Source File: BranchDataTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
Bus calcStarBusV1V2V3Y(BranchTestCase w1, BranchTestCase w2, BranchTestCase w3) { Complex v1 = ComplexUtils.polar2Complex(w1.bus1.u, w1.bus1.theta); Complex v2 = ComplexUtils.polar2Complex(w2.bus1.u, w2.bus1.theta); Complex v3 = ComplexUtils.polar2Complex(w3.bus1.u, w3.bus1.theta); Complex ytr1 = new Complex(w1.branch.end1.r, w1.branch.end1.x).reciprocal(); Complex ytr2 = new Complex(w2.branch.end1.r, w2.branch.end1.x).reciprocal(); Complex ytr3 = new Complex(w3.branch.end1.r, w3.branch.end1.x).reciprocal(); // FIXME consider tap.rho and tap.alpha Complex a01 = new Complex(w1.branch.end2.ratedU / w1.branch.end1.ratedU, 0); Complex a1 = new Complex(1, 0); Complex a02 = new Complex(w2.branch.end2.ratedU / w2.branch.end1.ratedU, 0); Complex a2 = new Complex(1, 0); Complex a03 = new Complex(w3.branch.end2.ratedU / w3.branch.end1.ratedU, 0); Complex a3 = new Complex(1, 0); Complex ysh01 = new Complex(w1.branch.end2.g, w1.branch.end2.b); Complex ysh02 = new Complex(w2.branch.end2.g, w2.branch.end2.b); Complex ysh03 = new Complex(w3.branch.end2.g, w3.branch.end2.b); Complex y01 = ytr1.negate().divide(a01.conjugate().multiply(a1)); Complex y02 = ytr2.negate().divide(a02.conjugate().multiply(a2)); Complex y03 = ytr3.negate().divide(a03.conjugate().multiply(a3)); Complex y0101 = ytr1.add(ysh01).divide(a01.conjugate().multiply(a01)); Complex y0202 = ytr2.add(ysh02).divide(a02.conjugate().multiply(a02)); Complex y0303 = ytr3.add(ysh03).divide(a03.conjugate().multiply(a03)); Complex v0 = y01.multiply(v1).add(y02.multiply(v2)).add(y03.multiply(v3)).negate() .divide(y0101.add(y0202).add(y0303)); Bus starBus = new Bus(); starBus.u = v0.abs(); starBus.theta = v0.getArgument(); return starBus; }
Example 10
Source File: TwtData.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private void calculateThreeConnectedLegsFlow(double u1, double theta1, double u2, double theta2, double u3, double theta3, LinkData.BranchAdmittanceMatrix branchAdmittanceLeg1, LinkData.BranchAdmittanceMatrix branchAdmittanceLeg2, LinkData.BranchAdmittanceMatrix branchAdmittanceLeg3) { Complex v1 = new Complex(u1 * Math.cos(theta1), u1 * Math.sin(theta1)); Complex v2 = new Complex(u2 * Math.cos(theta2), u2 * Math.sin(theta2)); Complex v3 = new Complex(u3 * Math.cos(theta3), u3 * Math.sin(theta3)); Complex v0 = branchAdmittanceLeg1.y21.multiply(v1).add(branchAdmittanceLeg2.y21.multiply(v2)) .add(branchAdmittanceLeg3.y21.multiply(v3)).negate() .divide(branchAdmittanceLeg1.y22.add(branchAdmittanceLeg2.y22).add(branchAdmittanceLeg3.y22)); LinkData.Flow flowLeg1 = LinkData.flowBothEnds(branchAdmittanceLeg1.y11, branchAdmittanceLeg1.y12, branchAdmittanceLeg1.y21, branchAdmittanceLeg1.y22, v1, v0); LinkData.Flow flowLeg2 = LinkData.flowBothEnds(branchAdmittanceLeg2.y11, branchAdmittanceLeg2.y12, branchAdmittanceLeg2.y21, branchAdmittanceLeg2.y22, v2, v0); LinkData.Flow flowLeg3 = LinkData.flowBothEnds(branchAdmittanceLeg3.y11, branchAdmittanceLeg3.y12, branchAdmittanceLeg3.y21, branchAdmittanceLeg3.y22, v3, v0); computedP1 = flowLeg1.fromTo.getReal(); computedQ1 = flowLeg1.fromTo.getImaginary(); computedP2 = flowLeg2.fromTo.getReal(); computedQ2 = flowLeg2.fromTo.getImaginary(); computedP3 = flowLeg3.fromTo.getReal(); computedQ3 = flowLeg3.fromTo.getImaginary(); starU = v0.abs(); starTheta = v0.getArgument(); }
Example 11
Source File: LoadFlowCaseGenerator.java From DeepMachineLearning with Apache License 2.0 | 4 votes |
protected void gotoLimit(AclfNetwork net) throws InterpssException { int busi = 9; System.out.println("============ Go to Limit ============"); LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net); AclfBus bus = net.getBusList().get(9); Complex base = bus.getLoadPQ(); Complex delta = base.multiply(10); Complex result = base; System.out.println("base = "+base+", delta = "+delta); if (bus.getContributeLoadList().size() == 0) return;//������cpf39����Э bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); System.out.println("\tbus load pq = "+bus.getLoadPQ()); int iter = 0; while(delta.abs() > 1e-10) { iter += 1; //��ǰ�������� System.out.println("base = "+base+", delta = "+delta); //��̽�е� delta = delta.multiply(0.5); bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); //�е����� System.out.println("bus load pq = "+bus.getLoadPQ()); //����̽�ɹ���... if (algo.loadflow()) { base = base.add(delta); result = base; System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ()); } // System.out.println(AclfOutFunc.loadFlowSummary(net)); } System.out.println("iter = "+iter); bus.getContributeLoadList().get(0).setLoadCP(result); System.out.println("after searching, bus 9 load PQ = "+result+", lf result = "+algo.loadflow()); System.out.println(AclfOutFunc.loadFlowSummary(net)); }
Example 12
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 13
Source File: TapChangerConversion.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
private static double impedanceConversion(double correction, Complex a) { double a2 = a.abs() * a.abs(); return correction * a2; }
Example 14
Source File: CpfCaseBuilder39.java From DeepMachineLearning with Apache License 2.0 | 4 votes |
private double gotoLimit2(AclfNetwork net) throws InterpssException { int busi = 15; System.out.println("============ Go to Limit ============"); LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net); algo.loadflow(); // LFOut.showlf(net); AclfBus bus = net.getBusList().get(busi); Complex base = bus.getLoadPQ(); oBase = bus.getLoadPQ(); Complex delta = base.multiply(100); Complex result = base; // System.out.println("base = "+base+", delta = "+delta); bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); System.out.println("\tbus 16 load pq = "+bus.getLoadPQ()); int iter = 0; while(delta.abs() > 1e-10) { iter += 1; //��ǰ�������� // System.out.println("base = "+base+", delta = "+delta); //��̽�е� delta = delta.multiply(0.5); bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); //�е����� // System.out.println("bus 9 load pq = "+bus.getLoadPQ()); //����̽�ɹ���... if (algo.loadflow()) { base = base.add(delta); result = base; // System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ()); } // System.out.println(AclfOutFunc.loadFlowSummary(net)); } // System.out.println("iter = "+iter); bus.getContributeLoadList().get(0).setLoadCP(result); System.out.println("after searching, bus 16 load PQ = "+result+", lf result = "+algo.loadflow()); // System.out.println(AclfOutFunc.loadFlowSummary(net)); return result.divide(oBase).abs(); }
Example 15
Source File: LfLimit.java From DeepMachineLearning with Apache License 2.0 | 4 votes |
public void go() throws InterpssException { LoadflowAlgorithm algo = CoreObjectFactory.createLoadflowAlgorithm(net); algo.loadflow(); System.out.println(AclfOutFunc.loadFlowSummary(net)); LFOut.showlf(net); // printNetStatus(); AclfBus bus = net.getBusList().get(9); Complex base = bus.getLoadPQ(); Complex delta = base.multiply(10); Complex result = base; System.out.println("base = "+base+", delta = "+delta); bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); System.out.println("\tbus load pq = "+bus.getLoadPQ()); int iter = 0; while(delta.abs() > 1e-10) { iter += 1; //��ǰ�������� System.out.println("base = "+base+", delta = "+delta); //��̽�е� delta = delta.multiply(0.5); bus.getContributeLoadList().get(0).setLoadCP(base.add(delta)); //�е����� System.out.println("bus load pq = "+bus.getLoadPQ()); //����̽�ɹ���... if (algo.loadflow()) { base = base.add(delta); result = base; System.out.println("a success bus 9 load PQ = "+bus.getLoadPQ()); } // System.out.println(AclfOutFunc.loadFlowSummary(net)); } System.out.println("iter = "+iter); bus.getContributeLoadList().get(0).setLoadCP(result); System.out.println("after searching, bus 9 load PQ = "+result+", lf result = "+algo.loadflow()); System.out.println(AclfOutFunc.loadFlowSummary(net)); LFOut.showlf(net); // printNetStatus(); }
Example 16
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 17
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 18
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 19
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * 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; }
Example 20
Source File: LaguerreSolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * 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; }