示例#1
0
        /// <summary>
        /// 给定函数FuncString类型 求值
        /// </summary>
        /// <param name="fs">必须得有参数 名字 表达式</param>
        /// <param name="nums">替换的参数</param>
        /// <returns>返回计算结果</returns>
        public double GetFuncResult(FuncString fs, params string[] nums)
        {        //这里的fs应该时是完整的?
            double result = 0;

            if (fs != null)
            {            //改一下
                FuncCal fc = new FuncCal();
                //				FuncString funs=tdc.GetData(fs).ConvertTOFunString();
                fc.SetFuncString(fs);
                fc.DealFuncstring(nums);
                result = fc.GetResult();

                if (fc.IsWrong())
                {
                    PushToShow(fc.ErrorMessage(), "error");
                }
            }
            return(result);
        }
示例#2
0
        public double FuncResult(string fs, TempDataCollection tdcl, params string[] nums)
        {
            double result = 0;

            if (fs != null)
            {
                PushToShow("有括号求值");
                FuncCal    fc   = new FuncCal();
                FuncString funs = tdcl.GetData(fs).ConvertTOFunString();
                fc.SetFuncString(funs);
                fc.DealFuncstring(nums);
                result = fc.GetResult();
                PushToShow("结果:" + fc.GetResult());
                if (fc.IsWrong())
                {
                    PushToShow("出错了!" + fc.ErrorMessage());
                }
            }
            return(result);
        }
示例#3
0
        public double FuncResult(string fs, TempDataCollection tdcl, params string[] nums)
        {
            double result = 0;

            if (fs != null)
            {
                PushToShow("有括号求值");
                FuncCal    fc   = new FuncCal();
                FuncData   fd   = (FuncData)tdc.GetData(fs).GetCalData();
                FuncString funs = new  FuncString(fs, fd.GetExpValue(), fd.GetParamers());
                fc.SetFuncString(funs);
                fc.DealFuncstring(nums);
                result = fc.GetResult();
                PushToShow("结果:" + fc.GetResult());
                if (fc.IsWrong())
                {
                    PushToShow("出错了!" + fc.ErrorMessage());
                }
            }
            return(result);
        }
示例#4
0
        //f(x,y)=x+y+t

        /// <summary>
        /// 替换已知变量,fstr是一个字符串表达式:x+y 不是f=x+y ,
        /// 没有变量是会原串返回的
        /// 里面找未知数时会调用底层 CalString 的函数,里面已经自动排除sin,cos,avg等 函数名了
        /// </summary>
        /// <param name="fstr">含参表达式</param>
        /// <param name="ps">排除变量</param>
        /// <returns>返回FuncExpressTemp为替换后的string
        /// 或含有未知变量返回null</returns>
        public static string ReplaceParamers(string fstr, string[] ps = null)
        {
            string[]   strarr = null;
            FuncString fs     = new FuncString(fstr);

//			fs.SetFuncExpressTemp(fstr);
            fs.SetFuncExpress(fstr);            //为向下兼容不出错


            FuncCal fc = new FuncCal();

            if (ps == null)
            {
                strarr = fs.FindUnKnown();
            }
            else
            {
                strarr = fs.FindUnKnown(ps);
            }

            fs.SetParamers(strarr);            //为向下兼容不出错,不明觉厉
            if (strarr.Length != 0)
            {
                PushToShow("含有未知数 尝试替换已知变量");
            }

            string[] paramersdata = new string[strarr.Length];
            fc.SetFuncString(fs);
            for (int i = 0; i < strarr.Length; i++)
            {
                if (tdc.CheckName(strarr[i]))
                {
                    CalData datatemp = tdc.GetData(strarr[i]).GetCalData();

                    switch (datatemp.CalType)
                    {
                    case DataType.BLOCK:
                    {
                        PushToShow("Type not match!");
                    }
                    break;

                    case DataType.EXP:
                    {
                        ExpData ed = (ExpData)datatemp;
                        paramersdata[i] = ed.GetValueEx();
                        PushToShow("提取" + strarr[i] + "的值:" + paramersdata[i]);
                        break;
                    }

                    case DataType.MATRIX:
                    {
                        Matrix matrix = (Matrix)datatemp;
                        PushToShow(matrix.ToString());
                    }
                    break;
                    }

//					if (datatemp.CalType == DataType.EXP) {
//						ExpData ed = (ExpData)datatemp;
//						paramersdata[i] = ed.GetValueEx();
//						PushToShow("提取" + strarr[i] + "的值:" + paramersdata[i]);
//					}
//
//					else
//						PushToShow("Type not match!");
                    continue;
                }

                PushToShow("未发现变量" + strarr[i] + "还未定义其值\n退出");
                return(null);
            }
            if (paramersdata.Length != 0)
            {
                fc.DealFuncstring(paramersdata);
            }
            else
            {
                fs.SetFuncExpressTemp(fstr);
            }
            return(fc.GetFuncString().GetFuncExpressTemp());
        }