org.apache.commons.math3.complex.ComplexUtils Java Examples

The following examples show how to use org.apache.commons.math3.complex.ComplexUtils. 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: Cascade.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
public Complex response(final double normalizedFrequency) {
    final double w = 2 * Math.PI * normalizedFrequency;
    final Complex czn1 = ComplexUtils.polar2Complex(1., -w);
    final Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
    Complex ch = new Complex(1);
    Complex cbot = new Complex(1);

    for (int i = 0; i < mNumBiquads; i++) {
        final Biquad stage = mBiquads[i];

        Complex ct = new Complex(stage.getB0() / stage.getA0()); // NOPMD
        ct = ct.add(czn1.multiply(stage.getB1() / stage.getA0()));
        ct = ct.add(czn2.multiply(stage.getB2() / stage.getA0()));

        Complex cb = new Complex(1); // NOPMD
        cb = cb.add(czn1.multiply(stage.getA1() / stage.getA0()));
        cb = cb.add(czn2.multiply(stage.getA2() / stage.getA0()));

        ch = ch.multiply(ct);
        cbot = cbot.multiply(cb);
    }

    return ch.divide(cbot);
}
 
Example #2
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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: LinkData.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public static BranchAdmittanceMatrix calculateBranchAdmittance(double r, double x, double ratio1, double alpha1,
    double ratio2, double alpha2, Complex ysh1, Complex ysh2) {

    Complex a1 = ComplexUtils.polar2Complex(ratio1, alpha1);
    Complex a2 = ComplexUtils.polar2Complex(ratio2, alpha2);

    Complex ytr;
    if (r == 0.0 && x == 0.0) {
        ytr = Complex.ZERO;
    } else {
        ytr = new Complex(r, x).reciprocal();
    }

    BranchAdmittanceMatrix branchAdmittance = new BranchAdmittanceMatrix();

    branchAdmittance.y11 = ytr.add(ysh1).divide(a1.conjugate().multiply(a1));
    branchAdmittance.y12 = ytr.negate().divide(a1.conjugate().multiply(a2));
    branchAdmittance.y21 = ytr.negate().divide(a2.conjugate().multiply(a1));
    branchAdmittance.y22 = ytr.add(ysh2).divide(a2.conjugate().multiply(a2));

    return branchAdmittance;
}
 
Example #5
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 vote down vote up
/**
 * 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: SV.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public SV otherSide(double r, double x, double g, double b, double ratio) {
    Complex z = new Complex(r, x); // z=r+jx
    Complex y = new Complex(g, b); // y=g+jb
    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 i2 = i1p.subtract(y.multiply(v1p)); // 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(Math.sqrt(3f));
    return new SV(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument()));
}
 
Example #8
Source File: SV.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
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 #9
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: Cascade.java    From iirj with Apache License 2.0 6 votes vote down vote up
public Complex response(double normalizedFrequency) {
	double w = 2 * Math.PI * normalizedFrequency;
	Complex czn1 = ComplexUtils.polar2Complex(1., -w);
	Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
	Complex ch = new Complex(1);
	Complex cbot = new Complex(1);

	for (int i = 0; i < m_numBiquads; i++) {
		Biquad stage = m_biquads[i];
		Complex cb = new Complex(1);
		Complex ct = new Complex(stage.getB0() / stage.getA0());
		ct = MathSupplement.addmul(ct, stage.getB1() / stage.getA0(), czn1);
		ct = MathSupplement.addmul(ct, stage.getB2() / stage.getA0(), czn2);
		cb = MathSupplement.addmul(cb, stage.getA1() / stage.getA0(), czn1);
		cb = MathSupplement.addmul(cb, stage.getA2() / stage.getA0(), czn2);
		ch = ch.multiply(ct);
		cbot = cbot.multiply(cb);
	}

	return ch.divide(cbot);
}
 
Example #11
Source File: Biquad.java    From iirj with Apache License 2.0 6 votes vote down vote up
public Complex response(double normalizedFrequency) {
    double a0 = getA0();
    double a1 = getA1();
    double a2 = getA2();
    double b0 = getB0();
    double b1 = getB1();
    double b2 = getB2();

    double w = 2 * Math.PI * normalizedFrequency;
    Complex czn1 = ComplexUtils.polar2Complex(1., -w);
    Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
    Complex ch = new Complex(1);
    Complex cbot = new Complex(1);

    Complex ct = new Complex(b0 / a0);
    Complex cb = new Complex(1);
    ct = MathSupplement.addmul(ct, b1 / a0, czn1);
    ct = MathSupplement.addmul(ct, b2 / a0, czn2);
    cb = MathSupplement.addmul(cb, a1 / a0, czn1);
    cb = MathSupplement.addmul(cb, a2 / a0, czn2);
    ch = ch.multiply(ct);
    cbot = cbot.multiply(cb);

    return ch.divide(cbot);
}
 
Example #12
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #13
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #14
Source File: Biquad.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public Complex response(final double normalizedFrequency) {
    final double a0 = getA0();
    final double a1 = getA1();
    final double a2 = getA2();
    final double b0 = getB0();
    final double b1 = getB1();
    final double b2 = getB2();

    final double w = 2 * Math.PI * normalizedFrequency;
    final Complex czn1 = ComplexUtils.polar2Complex(1., -w);
    final Complex czn2 = ComplexUtils.polar2Complex(1., -2 * w);
    Complex ch = new Complex(1);
    Complex cbot = new Complex(1);

    Complex ct = new Complex(b0 / a0);

    ct = ct.add(czn1.multiply(b1 / a0));
    ct = ct.add(czn2.multiply(b2 / a0));

    Complex cb = new Complex(1);
    cb = cb.add(czn1.multiply(a1 / a0));
    cb = cb.add(czn2.multiply(a2 / a0));

    ch = ch.multiply(ct);
    cbot = cbot.multiply(cb);

    return ch.divide(cbot);
}
 
Example #15
Source File: TransformerModel.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
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 #16
Source File: TransformerModel.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
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 #17
Source File: Butterworth.java    From iirj with Apache License 2.0 5 votes vote down vote up
public void design() {
	reset();
	double n2 = 2 * nPoles;
	int pairs = nPoles / 2;
	for (int i = 0; i < pairs; ++i) {
		Complex c = ComplexUtils.polar2Complex(1F, Math.PI/2.0
				+ (2 * i + 1) * Math.PI / n2);
		addPoleZeroConjugatePairs(c, Complex.INF);
	}

	if ((nPoles & 1) == 1)
		add(new Complex(-1), Complex.INF);
}
 
Example #18
Source File: Butterworth.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public void design() {
    reset();
    final double n2 = 2.0 * nPoles;
    final int pairs = nPoles / 2;
    for (int i = 0; i < pairs; ++i) {
        final Complex c = ComplexUtils.polar2Complex(1F, Math.PI / 2.0 + (2 * i + 1) * Math.PI / n2);
        addPoleZeroConjugatePairs(c, Complex.INF);
    }

    if ((nPoles & 1) == 1) {
        add(new Complex(-1), Complex.INF);
    }
}
 
Example #19
Source File: BranchDataTest.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
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 #20
Source File: StateVariablesAdder.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
private static Complex complexVoltage(double r, double x, double g, double b,
    double v, double angle, double p, double q) {
    BranchAdmittanceMatrix adm = LinkData.calculateBranchAdmittance(r, x, 1.0, 0.0, 1.0, 0.0,
        new Complex(g * 0.5, b * 0.5), new Complex(g * 0.5, b * 0.5));
    Complex v1 = ComplexUtils.polar2Complex(v, Math.toRadians(angle));
    Complex s1 = new Complex(p, q);
    return (s1.conjugate().divide(v1.conjugate()).subtract(adm.y11().multiply(v1))).divide(adm.y12());
}
 
Example #21
Source File: LinkData.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
static Flow flowBothEnds(Complex y11, Complex y12, Complex y21, Complex y22,
    double u1, double theta1, double u2, double theta2) {

    Complex v1 = ComplexUtils.polar2Complex(u1, theta1);
    Complex v2 = ComplexUtils.polar2Complex(u2, theta2);

    return flowBothEnds(y11, y12, y21, y22, v1, v2);
}
 
Example #22
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find a complex root for the polynomial with the given coefficients,
 * starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex solveComplex(double[] coefficients,
                            double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solve(ComplexUtils.convertToComplex(coefficients),
                               new Complex(initial, 0d));
}
 
Example #23
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex[] solveAllComplex(double[] coefficients,
                                 double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solveAll(ComplexUtils.convertToComplex(coefficients),
                                  new Complex(initial, 0d));
}
 
Example #24
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find a complex root for the polynomial with the given coefficients,
 * starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex solveComplex(double[] coefficients,
                            double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solve(ComplexUtils.convertToComplex(coefficients),
                               new Complex(initial, 0d));
}
 
Example #25
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex[] solveAllComplex(double[] coefficients,
                                 double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solveAll(ComplexUtils.convertToComplex(coefficients),
                                  new Complex(initial, 0d));
}
 
Example #26
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find a complex root for the polynomial with the given coefficients,
 * starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex solveComplex(double[] coefficients,
                            double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solve(ComplexUtils.convertToComplex(coefficients),
                               new Complex(initial, 0d));
}
 
Example #27
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex[] solveAllComplex(double[] coefficients,
                                 double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solveAll(ComplexUtils.convertToComplex(coefficients),
                                  new Complex(initial, 0d));
}
 
Example #28
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find a complex root for the polynomial with the given coefficients,
 * starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex solveComplex(double[] coefficients,
                            double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solve(ComplexUtils.convertToComplex(coefficients),
                               new Complex(initial, 0d));
}
 
Example #29
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find all complex roots for the polynomial with the given
 * coefficients, starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 * @since 3.1
 */
public Complex[] solveAllComplex(double[] coefficients,
                                 double initial)
    throws NullArgumentException,
           NoDataException,
           TooManyEvaluationsException {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solveAll(ComplexUtils.convertToComplex(coefficients),
                                  new Complex(initial, 0d));
}
 
Example #30
Source File: LaguerreSolver.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Find a complex root for the polynomial with the given coefficients,
 * starting from the given initial value.
 * <br/>
 * Note: This method is not part of the API of {@link BaseUnivariateSolver}.
 *
 * @param coefficients Polynomial coefficients.
 * @param initial Start value.
 * @return the point at which the function value is zero.
 * @throws org.apache.commons.math3.exception.TooManyEvaluationsException
 * if the maximum number of evaluations is exceeded.
 * @throws NullArgumentException if the {@code coefficients} is
 * {@code null}.
 * @throws NoDataException if the {@code coefficients} array is empty.
 */
public Complex solveComplex(double[] coefficients,
                            double initial) {
    setup(Integer.MAX_VALUE,
          new PolynomialFunction(coefficients),
          Double.NEGATIVE_INFINITY,
          Double.POSITIVE_INFINITY,
          initial);
    return complexSolver.solve(ComplexUtils.convertToComplex(coefficients),
                               new Complex(initial, 0d));
}