public MathFunc(string str, string v = null, bool simplify = true, bool precompile = false)
        {
            List <MathFunc> mathFuncs = new MathExprConverter().Convert(str);
            MathFunc        first     = mathFuncs.FirstOrDefault();

            LeftNode  = first.LeftNode;
            RightNode = first.RightNode;
            Root      = RightNode;

            if (string.IsNullOrEmpty(v))
            {
                ConstToVars();
            }
            else
            {
                Variable = new VarNode(v);
                ConstToVar(Root);
            }

            FindParamsAndUnknownFuncs(Root);

            Root.Sort();
            if (simplify)
            {
                Root = Simplify(Root);
            }
            if (precompile)
            {
                Root = Precompile(null, Root);
            }
        }
Exemple #2
0
        private void CompileFuncAndDerivative(string expression, string variable, string name = "")
        {
            var func    = new MathFunc(expression, variable, true, true);
            var funcDer = new MathFunc(expression, variable, true, false).GetDerivative().GetPrecompilied();

            Init(name);

            func.Compile(this, FuncName);
            funcDer.Compile(this, FuncDerivativeName);
        }
		public void CompileFuncAndDerivative(string expression, string variable, string path = "", string fileName = "")
		{
			var func = new MathFunc(expression, variable, true, true);
			var funcDer = new MathFunc(expression, variable, true, false).GetDerivative().GetPrecompilied();

			Init(fileName);

			func.Compile(this, FuncName);
			funcDer.Compile(this, FuncDerivativeName);

			Finalize(path, fileName);
		}
Exemple #4
0
        public MathFunc Generate(string varName, string[] constNames, string[] unknownFuncNames)
        {
            bool     error  = false;
            MathFunc result = null;

            do
            {
                error = false;
                try
                {
                    result = new MathFunc(Generate(0, varName, constNames, unknownFuncNames), new VarNode(varName));
                    var precompilied = new MathFunc(result.ToString(), varName, true, true);
                    if (precompilied.ContainsNaN())
                    {
                        error = true;
                    }
                }
                catch
                {
                    error = true;
                }
            }while (error);
            return(result);
        }
        private void CompileFuncAndDerivative(string expression, string variable, string name = "")
        {
            var func = new MathFunc(expression, variable, true, true);
            var funcDer = new MathFunc(expression, variable, true, false).GetDerivative().GetPrecompilied();

            Init(name);

            func.Compile(this, FuncName);
            funcDer.Compile(this, FuncDerivativeName);
        }