コード例 #1
0
ファイル: LambdaALGSYS.cs プロジェクト: Allisrazor/symbcs
        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);
        }