Example #1
0
        PartialFractionDecomposition(
            WWComplex [] nCoeffs, WWComplex [] dRoots)
        {
            var result = new List <FirstOrderComplexRationalPolynomial>();

            if (dRoots.Length == 1 && nCoeffs.Length == 1)
            {
                result.Add(new FirstOrderComplexRationalPolynomial(WWComplex.Zero(),
                                                                   nCoeffs[0], WWComplex.Unity(), WWComplex.Minus(dRoots[0])));
                return(result);
            }

            if (dRoots.Length < 2)
            {
                throw new ArgumentException("denomR");
            }
            if (dRoots.Length < nCoeffs.Length)
            {
                throw new ArgumentException("nCoeffs");
            }

            for (int k = 0; k < dRoots.Length; ++k)
            {
                // cn = ... + nCoeffs[2]s^2 + nCoeffs[1]s + nCoeffs[0]
                // 係数c[0]は、s==denomR[0]としたときの、cn/(s-denomR[1])(s-denomR[2])(s-denomR[3])…(s-denomR[p-1])
                // 係数c[1]は、s==denomR[1]としたときの、cn/(s-denomR[0])(s-denomR[2])(s-denomR[3])…(s-denomR[p-1])
                // 係数c[2]は、s==denomR[2]としたときの、cn/(s-denomR[0])(s-denomR[1])(s-denomR[3])…(s-denomR[p-1])

                // 分子の値c。
                var c = WWComplex.Zero();
                var s = WWComplex.Unity();
                for (int j = 0; j < nCoeffs.Length; ++j)
                {
                    c = WWComplex.Add(c, WWComplex.Mul(nCoeffs[j], s));
                    s = WWComplex.Mul(s, dRoots[k]);
                }

                for (int i = 0; i < dRoots.Length; ++i)
                {
                    if (i == k)
                    {
                        continue;
                    }

                    c = WWComplex.Div(c, WWComplex.Sub(dRoots[k], dRoots[i]));
                }

                result.Add(new FirstOrderComplexRationalPolynomial(
                               WWComplex.Zero(), c,
                               WWComplex.Unity(), WWComplex.Minus(dRoots[k])));
            }

            return(result);
        }
Example #2
0
            public void Print(string x)
            {
                if (0 < coeffList.Length)
                {
                    bool bFirst = true;
                    for (int i = coeffList.Length - 1; 0 <= i; --i)
                    {
                        if (coeffList[i].AlmostZero())
                        {
                            continue;
                        }

                        if (bFirst)
                        {
                            bFirst = false;
                        }
                        else
                        {
                            Console.Write(" + ");
                        }

                        if (i == 0)
                        {
                            Console.Write("{0}", coeffList[i]);
                        }
                        else if (i == 1)
                        {
                            Console.Write("{0}*{1}", coeffList[i], x);
                        }
                        else
                        {
                            Console.Write("{0}*({1}^{2})", coeffList[i], x, i);
                        }
                    }
                    if (!bFirst)
                    {
                        Console.Write(" + ");
                    }
                }

                Console.Write(" { ");
                {
                    bool bFirst = true;
                    for (int i = numerCoeffList.Length - 1; 0 <= i; --i)
                    {
                        if (numerCoeffList[i].AlmostZero())
                        {
                            continue;
                        }

                        if (bFirst)
                        {
                            bFirst = false;
                        }
                        else
                        {
                            Console.Write(" + ");
                        }
                        if (i == 0)
                        {
                            Console.Write("{0}", numerCoeffList[i]);
                        }
                        else if (i == 1)
                        {
                            Console.Write("{0}*{1}", numerCoeffList[i], x);
                        }
                        else
                        {
                            Console.Write("{0}*({1}^{2})", numerCoeffList[i], x, i);
                        }
                    }
                }

                Console.Write(" } / { ");

                {
                    for (int i = 0; i < denomRootList.Length; ++i)
                    {
                        if (denomRootList[i].AlmostZero())
                        {
                            Console.WriteLine(" {0} ", x);
                            continue;
                        }

                        Console.Write("({0}+({1}))", x, WWComplex.Minus(denomRootList[i]));
                    }
                }
                Console.WriteLine(" }");
            }