Beispiel #1
0
        private void Test(string[] args)
        {
            double[] ar = { 0.0, 1.0, 1.0, 1.0 };
            double[] ai = { 0.0, 0.0, 1.0, 0.0 };

            bool[] err = { true, true, true, true };

            Pzeros.aberth(ar, ai, err);

            for (int i = 0; i < ar.Length - 1; i++)
            {
                println(@"{0}: {1}+i*{2}  {3}", i, ar[i], ai[i], err[i]);
            }
        }
Beispiel #2
0
    public static void Test(string[] args)
    {
        double[] ar = { 0.0, 1.0, 1.0, 1.0 };
        double[] ai = { 0.0, 0.0, 1.0, 0.0 };

        bool[] err = { true, true, true, true };

        Pzeros.aberth(ar, ai, err);

        for (int i = 0; i < ar.Length - 1; i++)
        {
            Console.WriteLine(@"{0}: {1}+i*{2}  {3}", i, ar[i], ai[i], err[i]);
        }
    }
Beispiel #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Vektor roots() throws JasymcaException
    public virtual Vektor roots()
    {
        if (a.Length == 2)
        {
            Algebraic[] result = new Algebraic[] { a[0].mult(Zahl.MINUS).div(a[1]) };
            return(new Vektor(result));
        }
        else if (a.Length == 3)
        {
            return(new Vektor(Poly.pqsolve(a[1].div(a[2]), a[0].div(a[2]))));
        }
        double[] ar      = new double[a.Length];
        double[] ai      = new double[a.Length];
        bool[]   err     = new bool[a.Length];
        bool     komplex = false;

        for (int i = 0; i < a.Length; i++)
        {
            Algebraic cf = a[i];
            if (!(cf is Zahl))
            {
                throw new JasymcaException("Roots requires constant coefficients.");
            }
            ar[i] = ((Zahl)cf).unexakt().real;
            ai[i] = ((Zahl)cf).unexakt().imag;
            if (ai[i] != 0.0)
            {
                komplex = true;
            }
        }
        if (komplex)
        {
            Pzeros.aberth(ar, ai, err);
        }
        else
        {
            Pzeros.bairstow(ar, ai, err);
            bool ok = true;
            for (int i = 0; i < err.Length - 1; i++)
            {
                if (err[i])
                {
                    ok = false;
                }
            }
            if (!ok)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    Algebraic cf = a[i];
                    ar[i] = ((Zahl)cf).unexakt().real;
                    ai[i] = ((Zahl)cf).unexakt().imag;
                }
                Pzeros.aberth(ar, ai, err);
            }
        }
        Algebraic[] r = new Algebraic[a.Length - 1];
        for (int i = 0; i < r.Length; i++)
        {
            if (!err[i])
            {
                Unexakt x0 = new Unexakt(ar[i], ai[i]);
                r[i] = x0;
            }
            else
            {
                throw new JasymcaException("Could not calculate root " + i);
            }
        }
        return(new Vektor(r));
    }
Beispiel #4
0
    public virtual Vector roots()
    {
        if (Coeffs.Length == 2)
        {
            return(new Vector(new[] { -Coeffs[0] / Coeffs[1] }));
        }
        else if (Coeffs.Length == 3)
        {
            return(new Vector(Poly.pqsolve(Coeffs[1] / Coeffs[2], Coeffs[0] / Coeffs[2])));
        }

        var ar = new double[Coeffs.Length];
        var ai = new double[Coeffs.Length];

        var err     = new bool[Coeffs.Length];
        var komplex = false;

        for (int i = 0; i < Coeffs.Length; i++)
        {
            var cf = Coeffs[i];

            if (!(cf is Symbolic))
            {
                throw new JasymcaException("Roots requires constant coefficients.");
            }

            ar[i] = ((Symbolic)cf).ToComplex().Re;
            ai[i] = ((Symbolic)cf).ToComplex().Im;

            if (ai[i] != 0.0)
            {
                komplex = true;
            }
        }

        if (komplex)
        {
            Pzeros.aberth(ar, ai, err);
        }
        else
        {
            Pzeros.bairstow(ar, ai, err);

            bool ok = true;

            for (int i = 0; i < err.Length - 1; i++)
            {
                if (err[i])
                {
                    ok = false;
                }
            }

            if (!ok)
            {
                for (int i = 0; i < Coeffs.Length; i++)
                {
                    Algebraic cf = Coeffs[i];

                    ar[i] = ((Symbolic)cf).ToComplex().Re;
                    ai[i] = ((Symbolic)cf).ToComplex().Im;
                }

                Pzeros.aberth(ar, ai, err);
            }
        }

        var r = new Algebraic[Coeffs.Length - 1];

        for (int i = 0; i < r.Length; i++)
        {
            if (!err[i])
            {
                var x0 = new Complex(ar[i], ai[i]);

                r[i] = x0;
            }
            else
            {
                throw new JasymcaException("Could not calculate root " + i);
            }
        }

        return(new Vector(r));
    }
Beispiel #5
0
 public doublecomplex(Pzeros outerInstance, double r, double i)
 {
     this.outerInstance = outerInstance;
     this.r             = r;
     this.i             = i;
 }