Exemple #1
0
 internal override Algebraic SymEval(Algebraic x)
 {
     if (x.Equals(Symbol.ZERO))
     {
         return(Symbol.ZERO);
     }
     return(null);
 }
Exemple #2
0
        internal override Algebraic SymEval(Algebraic x)
        {
            if (x.Equals(Symbol.ONE))
            {
                return(Symbol.ZERO);
            }

            if (x.Equals(Symbol.MINUS))
            {
                return(Symbol.PI * Symbol.IONE);
            }

            if (x is Polynomial &&
                (( Polynomial )x).Degree() == 1 &&
                (( Polynomial )x)[0].Equals(Symbol.ZERO) &&
                (( Polynomial )x).Var is FunctionVariable &&
                (( FunctionVariable )(( Polynomial )x).Var).Name.Equals("exp"))
            {
                return((( FunctionVariable )(( Polynomial )x).Var).Var + FunctionVariable.Create("log", (( Polynomial )x)[1]));
            }

            return(null);
        }
Exemple #3
0
        internal override Algebraic SymEval(Algebraic x, Algebraic y)
        {
            if (x.Equals(Symbol.ZERO))
            {
                if (y.Equals(Symbol.ZERO))
                {
                    return(Symbol.ONE);
                }

                return(Symbol.ZERO);
            }

            if (y is Symbol && (( Symbol )y).IsInteger())
            {
                return(x.Pow((( Symbol )y).ToInt()));
            }

            return(FunctionVariable.Create("exp", FunctionVariable.Create("log", x) * y));
        }
Exemple #4
0
        private static void subst(Vector expr, Vector vars, int n)
        {
            if (n < 0)
            {
                return;
            }
            var pa = expr[n];

            if (pa is Polynomial)
            {
                var       p = ( Polynomial )pa;
                Variable  v = null;
                Algebraic c1 = null, c0;
                for (int k = 0; k < vars.Length(); k++)
                {
                    var va = (( Polynomial )vars[k]).Var;
                    c1 = p.GetCoeff(va, 1);
                    if (!c1.Equals(Symbol.ZERO))
                    {
                        v = va;
                        break;
                    }
                }
                if (v != null)
                {
                    expr[n] = p / c1;

                    var val = -p.GetCoeff(v, 0) / c1;

                    for (int k = 0; k < n; k++)
                    {
                        var ps = expr[k];
                        if (ps is Polynomial)
                        {
                            expr.set(k, (( Polynomial )ps).Value(v, val));
                        }
                    }
                }
            }
            subst(expr, vars, n - 1);
        }
Exemple #5
0
        protected override Algebraic Mul(Algebraic x)
        {
            if (x.Equals(Symbol.ZERO))
            {
                return(x);
            }

            if (x is Symbol)
            {
                return(new Exponential(this[1] * x, this[0] * x, expvar, exp_b));
            }

            if (x is Exponential && expvar.Equals((( Exponential )x).expvar))
            {
                var xp = ( Exponential )x;

                Algebraic r = Symbol.ZERO;

                var nex = exp_b + xp.exp_b;

                if (Equals(nex, Symbol.ZERO))
                {
                    r = this[1] * xp[1];
                }
                else
                {
                    r = new Exponential(this[1] * xp[1], Symbol.ZERO, expvar, nex);
                }

                r = r + this[0] * xp;

                r = r + this * xp[0];

                r = r.Reduce();

                return(r);
            }

            return(poly2exp(this * x));
        }
Exemple #6
0
        internal override Algebraic SymEval(Algebraic x)
        {
            if (x.Equals(Symbol.ZERO))
            {
                return(Symbol.ONE);
            }

            if (x is Polynomial &&
                (( Polynomial )x).Degree() == 1 &&
                (( Polynomial )x)[0].Equals(Symbol.ZERO))
            {
                var xp = ( Polynomial )x;

                if (xp.Var is SimpleVariable && (( SimpleVariable )xp.Var).name.Equals("pi"))
                {
                    var q = xp[1] / Symbol.IONE;

                    if (q is Symbol)
                    {
                        return(fzexakt(( Symbol )q));
                    }
                }

                if (xp[1] is Symbol &&
                    xp.Var is FunctionVariable &&
                    (( FunctionVariable )xp.Var).Name.Equals("log"))
                {
                    if ((( Symbol )xp[1]).IsInteger())
                    {
                        int n = (( Symbol )xp[1]).ToInt();

                        return((( FunctionVariable )xp.Var).Var.Pow(n));
                    }
                }
            }

            return(null);
        }
Exemple #7
0
        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(Symbol.ZERO) && slope is Symbol)
                    {
                        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 SymbolicException("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);
        }