Exemplo n.º 1
0
        AlgebraicLongDivision(RealPolynomial dividend, RealPolynomial divisor)
        {
            if (dividend.Degree < divisor.Degree)
            {
                throw new ArgumentException("dividendCoef degree is smaller than divisorCoef");
            }
            AllRealDivisionResult r = new AllRealDivisionResult();

            var quotient  = new double [dividend.Degree - divisor.Degree + 1];
            var divRemain = new double[dividend.Degree + 1];

            for (int i = 0; i < divRemain.Length; ++i)
            {
                divRemain[i] = dividend.C(i);
            }
            for (int i = 0; i < quotient.Length; ++i)
            {
                double q = divRemain[dividend.Degree - i]
                           / divisor.C(divisor.Degree);
                quotient[quotient.Length - 1 - i] = q;
                for (int j = 0; j <= divisor.Degree; ++j)
                {
                    divRemain[dividend.Degree - i - j] -=
                        q * divisor.C(divisor.Degree - j);
                }
            }

            r.quotient  = new RealPolynomial(quotient);
            r.remainder = new RealRationalPolynomial(
                new RealPolynomial(divRemain).RemoveLeadingZeros(),
                divisor.RemoveLeadingZeros());
            return(r);
        }
Exemplo n.º 2
0
        public RealRationalPolynomial(RealPolynomial aNumer, RealPolynomial aDenom)
        {
            numer = new double[aNumer.Degree + 1];
            denom = new double[aDenom.Degree + 1];

            for (int i = 0; i < numer.Length; ++i)
            {
                numer[i] = aNumer.C(i);
            }

            for (int i = 0; i < denom.Length; ++i)
            {
                denom[i] = aDenom.C(i);
            }
        }
Exemplo n.º 3
0
        public static RealPolynomial Add(RealPolynomial l, RealPolynomial r)
        {
            int degree = (l.Degree < r.Degree) ? r.Degree : l.Degree;
            var c      = new double[degree + 1];

            for (int i = 0; i <= degree; ++i)
            {
                c[i] = 0;
                if (i <= l.Degree)
                {
                    c[i] += l.C(i);
                }
                if (i <= r.Degree)
                {
                    c[i] += r.C(i);
                }
            }
            return(new RealPolynomial(c));
        }
Exemplo n.º 4
0
        Mul(RealPolynomial lhs, RealPolynomial rhs)
        {
            // 1次 p 2次 = 3次
            // 2次 p 2次 = 4次
            // 2次 p 3次 = 5次

            // (p^2+2x+3) * (4x+5)

            var c = new double[lhs.Degree + rhs.Degree + 1];

            // C#では、cの要素は0で初期化される。

            for (int iL = 0; iL <= lhs.Degree; ++iL)
            {
                for (int iR = 0; iR <= rhs.Degree; ++iR)
                {
                    c[iL + iR] += lhs.C(iL) * rhs.C(iR);
                }
            }

            return(new RealPolynomial(c));
        }