Ejemplo n.º 1
0
        //-----------------------------------------------------------------------------------------
        //Корни уравнения
        public static Complex[] GetRoots(double a, double b, double c, double d)
        {
            CubicEquation cubicEquation = new CubicEquation(a, b, c, d);

            Complex[] roots = cubicEquation.GetRoots();
            return(roots);
        }
Ejemplo n.º 2
0
        //-----------------------------------------------------------------------------------------
        public Complex[] GetRoots()
        {
            double bb = this.b / this.a;
            double cc = this.c / this.a;
            double dd = this.d / this.a;
            double ee = this.e / this.a;

            double f = cc - 3 * bb * bb / 8;
            double g = dd + bb * bb * bb / 8 - bb * cc / 2;
            double h = ee - 3 * bb * bb * bb * bb / 256 + bb * bb * cc / 16 - bb * dd / 4;

            Complex[] cubicEquationRoots =
                CubicEquation.GetRoots(1, f / 2, (f * f - 4 * h) / 16, -g * g / 64);

            Complex p = Complex.Sqrt(cubicEquationRoots[1]);
            Complex q = Complex.Sqrt(cubicEquationRoots[2]);

            Complex r = -g / (8 * p * q);
            Complex s = b / (4 * a);

            Complex x1 = p + q + r - s;
            Complex x2 = p - q - r - s;
            Complex x3 = -p + q - r - s;
            Complex x4 = -p - q + r - s;

            Complex[] roots = new Complex[] { x1, x2, x3, x4 };
            return(roots);
        }