public HighOrderComplexRationalPolynomial(FirstOrderComplexRationalPolynomial uni)
        {
            int numerCount = 1;

            if (1 == uni.NumerDegree())
            {
                numerCount = 2;
            }
            numer = new WWComplex[numerCount];
            for (int i = 0; i < numerCount; ++i)
            {
                numer[i] = uni.N(i);
            }

            int denomCount = 1;

            if (1 == uni.DenomDegree())
            {
                denomCount = 2;
            }
            denom = new WWComplex[denomCount];
            for (int i = 0; i < denomCount; ++i)
            {
                denom[i] = uni.D(i);
            }
        }
Exemplo n.º 2
0
        MulComplexConjugatePair(FirstOrderComplexRationalPolynomial p0)
        {
            if (p0.NumerDegree() != 1 || p0.DenomDegree() != 1)
            {
                throw new ArgumentException("p0");
            }

            var n0 = p0.NumerCoeffs();
            var d0 = p0.DenomCoeffs();

            // n1, d1 : 共役の多項式の係数
            var n1 = new WWComplex[2];

            for (int i = 0; i < 2; ++i)
            {
                n1[i] = n0[i].ComplexConjugate();
            }

            var d1 = new WWComplex[2];

            for (int i = 0; i < 2; ++i)
            {
                d1[i] = d0[i].ComplexConjugate();
            }

            var n = new double[3];

            n[0] = WWComplex.Mul(n0[0], n1[0]).real;
            n[1] = WWComplex.Add(WWComplex.Mul(n0[0], n1[1]), WWComplex.Mul(n0[1], n1[0])).real;
            n[2] = WWComplex.Mul(n0[1], n1[1]).real;

            var d = new double[3];

            d[0] = WWComplex.Mul(d0[0], d1[0]).real;
            d[1] = WWComplex.Add(WWComplex.Mul(d0[0], d1[1]), WWComplex.Mul(d0[1], d1[0])).real;
            d[2] = WWComplex.Mul(d0[1], d1[1]).real;

            return(new RealRationalPolynomial(n, d));
        }
Exemplo n.º 3
0
        Add(HighOrderComplexRationalPolynomial lhs, FirstOrderComplexRationalPolynomial rhs)
        {
            /*  nL          nR
             * p^2+2x+2    p+4
             * ───────── + ────
             * p^2+ p+1    p+3
             *  dL          dR
             *
             *          dL       dR
             * 分母 = (p^2+p+1) (p+3)
             * 分母の次数 = degree(dL) + degree(dR) + 1
             *
             *          nL       dR      nR    dL
             * 分子 = (p^2+2x+2)(p+3) + (p+4)(p^2+p+1)
             * 分子の次数 = degree(nL) + degree(dR) + 1 か degree(nR) * degree(dL) + 1の大きいほう
             */

            ComplexPolynomial denomL;
            {
                var d = new WWComplex[lhs.DenomDegree() + 1];
                for (int i = 0; i <= lhs.DenomDegree(); ++i)
                {
                    d[i] = lhs.D(i);
                }
                denomL = new ComplexPolynomial(d);
            }
            ComplexPolynomial numerL;
            {
                var n = new WWComplex[lhs.NumerDegree() + 1];
                for (int i = 0; i <= lhs.NumerDegree(); ++i)
                {
                    n[i] = lhs.N(i);
                }
                numerL = new ComplexPolynomial(n);
            }

            // 分母の項
            ComplexPolynomial denomResult;
            {
                var denomX = new ComplexPolynomial(new WWComplex[0]);
                if (1 == rhs.DenomDegree())
                {
                    denomX = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(denomL), rhs.D(1));
                }
                var denomC = ComplexPolynomial.MultiplyC(denomL, rhs.D(0));
                denomResult = ComplexPolynomial.Add(denomX, denomC);
            }

            // 分子の項
            ComplexPolynomial numerResult;

            {
                ComplexPolynomial numer0;
                {
                    var numerX0 = new ComplexPolynomial(new WWComplex[0]);
                    if (1 == rhs.DenomDegree())
                    {
                        numerX0 = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(numerL), rhs.D(1));
                    }
                    var numerC0 = ComplexPolynomial.MultiplyC(numerL, rhs.D(0));
                    numer0 = ComplexPolynomial.Add(numerX0, numerC0);
                }

                ComplexPolynomial numer1;
                {
                    var numerX1 = new ComplexPolynomial(new WWComplex[0]);
                    if (1 == rhs.NumerDegree())
                    {
                        numerX1 = ComplexPolynomial.MultiplyC(ComplexPolynomial.MultiplyX(denomL), rhs.N(1));
                    }
                    var numerC1 = ComplexPolynomial.MultiplyC(denomL, rhs.N(0));
                    numer1 = ComplexPolynomial.Add(numerX1, numerC1);
                }

                numerResult = ComplexPolynomial.Add(numer0, numer1);
            }

            return(new HighOrderComplexRationalPolynomial(numerResult.ToArray(), denomResult.ToArray()));
        }