Beispiel #1
0
    internal static Algebraic remove_constant(Algebraic expr, Variable x)
    {
        if (!expr.Depends(x))
        {
            return(Symbolic.ZERO);
        }

        if (expr is Polynomial)
        {
            (( Polynomial )expr)[0] = remove_constant((( Polynomial )expr)[0], x);

            return(expr);
        }

        if (expr is Rational)
        {
            var den = (( Rational )expr).den;
            var nom = (( Rational )expr).nom;

            if (!den.Depends(x))
            {
                return(remove_constant(nom, x) / den);
            }

            if (nom is Polynomial)
            {
                var a = new[] { nom, den };

                Poly.polydiv(a, den._v);

                if (!a[0].Depends(x))
                {
                    return(a[1] / den);
                }
            }
        }

        return(expr);
    }
Beispiel #2
0
    public virtual Algebraic ratsubst(Algebraic expr)
    {
        if (gcd.Equals(Symbolic.ZERO))
        {
            return(expr);
        }
        if (!expr.Depends(@var))
        {
            return(expr);
        }
        if (expr is Rational)
        {
            return(ratsubst((( Rational )expr).nom) / ratsubst((( Rational )expr).den));
        }

        if (expr is Polynomial && ((Polynomial)expr)._v is FunctionVariable &&
            ((FunctionVariable)((Polynomial)expr)._v).Name.Equals("exp") &&
            ((FunctionVariable)((Polynomial)expr)._v).Var is Polynomial &&
            ((Polynomial)((FunctionVariable)((Polynomial)expr)._v).Var)._v.Equals(@var) &&
            ((Polynomial)((FunctionVariable)((Polynomial)expr)._v).Var).Degree() == 1 &&
            ((Polynomial)((FunctionVariable)((Polynomial)expr)._v).Var)[0].Equals(Symbolic.ZERO))
        {
            Polynomial  pexpr  = (Polynomial)expr;
            int         degree = pexpr.Degree();
            Algebraic[] a      = new Algebraic[degree + 1];
            for (int i = 0; i <= degree; i++)
            {
                Algebraic cf = pexpr[i];
                if (cf.Depends(@var))
                {
                    throw new JasymcaException("Rationalize failed: 2");
                }
                a[i] = cf;
            }
            return(new Polynomial(t, a));
        }
        throw new JasymcaException("Could not rationalize " + expr);
    }
Beispiel #3
0
 public override bool Depends(Variable v)
 {
     return(nom.Depends(v) || den.Depends(v));
 }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: Vektor solve(Vector expr, Vector x, int n) throws JasymcaException
    internal virtual Vector solve(ArrayList expr, ArrayList x, int n)
    {
        Algebraic equ = null;
        Variable  v = null;
        int       i, k, iv = 0, ke = 0;

        for (i = 0; i < n && equ == null; i++)
        {
            v = (Variable)x[i];
            double norm = -1.0;
            for (k = 0; k < n; k++)
            {
                Algebraic exp = (Algebraic)expr[k];
                if (exp is Rational)
                {
                    exp = ((Rational)exp).nom;
                }
                Algebraic slope = exp.Derive(v);
                if (!slope.Equals(Symbolic.ZERO) && slope is Symbolic)
                {
                    double nm = slope.Norm() / exp.Norm();
                    if (nm > norm)
                    {
                        norm = nm;
                        equ  = exp;
                        ke   = k;
                        iv   = i;
                    }
                }
            }
        }
        if (equ == null)
        {
            for (i = 0; i < n && equ == null; i++)
            {
                v = (Variable)x[i];
                for (k = 0; k < n; k++)
                {
                    Algebraic exp = (Algebraic)expr[k];
                    if (exp is Rational)
                    {
                        exp = ((Rational)exp).nom;
                    }
                    if (exp.Depends(v))
                    {
                        equ = exp;
                        ke  = k;
                        iv  = i;
                        break;
                    }
                }
            }
        }
        if (equ == null)
        {
            throw new JasymcaException("Expressions do not depend of Variables.");
        }
        Vector sol = LambdaSOLVE.solve(equ, v);

        expr.RemoveAt(ke);
        expr.Insert(n - 1, equ);
        x.RemoveAt(iv);
        x.Insert(n - 1, v);
        return(sol);
    }