当前位置: 首页>>代码示例>>C#>>正文


C# Parser.Calculate方法代码示例

本文整理汇总了C#中Parser.Calculate方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Calculate方法的具体用法?C# Parser.Calculate怎么用?C# Parser.Calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser.Calculate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Iterative

        public static string Iterative(string sfx, string sfdx, double a, double b, out int count)
        {
            Parser fx = new Parser(sfx);
            fx.AddFunction<Algorithms>("log");
            fx.Compile();
            Parser fdx = new Parser(sfdx);
            fdx.AddFunction<Algorithms>("log");
            fdx.Compile();

            double x0 = (a + b)/2;
            if (x0 == 0)
            {
                x0 = (b + x0)/2;
            }
            fdx.Variables.Add("x", x0);

            double lambda = -1 / fdx.Calculate();

            count = 0;
            fx.Variables.Add("x", x0);
            double xn = x0 + lambda*fx.Calculate();

            while ((xn - x0) > eps)
            {
                x0 = xn;
                fx.Variables["x"] = xn;
                xn = xn + lambda * fx.Calculate();
                ++count;
            }

            return xn.ToString();
        }
开发者ID:osst,项目名称:University,代码行数:32,代码来源:Form1.cs

示例2: Parse

 public static double Parse(string input)
 {
     Parser OMG = new Parser(input);
      OMG.AddFunction<Agent>("F");
      OMG.Compile();
      OMG.Variables.Add("x",2);
      OMG.Variables.Add("y", 2);
      OMG.Variables.Add("z", 2);
      return OMG.Calculate();
 }
开发者ID:osst,项目名称:University,代码行数:10,代码来源:Tests.cs

示例3: Chord

        public static string Chord(string sfx, string sfdx, double a, double b, out int count)
        {
            Parser fx = new Parser(sfx);
            fx.AddFunction<Algorithms>("log");
            fx.Compile();
            Parser fdx = new Parser(sfdx);
            fdx.AddFunction<Algorithms>("log");
            fdx.Compile();

            fx.Variables["x"] = a;
            fdx.Variables["x"] = a;
            double a_fpt = fx.Calculate()*fdx.Calculate();

            fx.Variables["x"] = b;
            fdx.Variables["x"] = b;
            double b_fpt = fx.Calculate()*fdx.Calculate();

            double fixedPoint = a_fpt > 0 ? a : b;

            double xnm1 = (a + b) / 2;
            fx.Variables["x"] = xnm1;
            double fx_r = fx.Calculate();
            fx.Variables["x"] = fixedPoint;
            double fx0_r = fx.Calculate();
            double xn = xnm1 - (xnm1 - fixedPoint)/(fx_r - fx0_r)*fx_r;

            count = 0;

            while ((xn - xnm1) > eps)
            {
                xnm1 = xn;

                fx.Variables["x"] = xn;
                fx_r = fx.Calculate();

                xn = xn - (xn - fixedPoint) / (fx_r - fx0_r) * fx_r;
                ++count;
            }

            return xn.ToString();
        }
开发者ID:osst,项目名称:University,代码行数:41,代码来源:Form1.cs

示例4: Newton

        public static string Newton(string sfx, string sfdx, string sfddx, double a, double b, out int count)
        {
            Parser fx = new Parser(sfx);
            fx.AddFunction<Algorithms>("log");
            fx.Compile();
            Parser fdx = new Parser(sfdx);
            fdx.AddFunction<Algorithms>("log");
            fdx.Compile();
            Parser fddx = new Parser(sfddx);
            fddx.AddFunction<Algorithms>("log");
            fdx.Compile();

            fx.Variables["x"] = a;
            fddx.Variables["x"] = a;
            double a_fpt = fx.Calculate() * fddx.Calculate();

            fx.Variables["x"] = b;
            fddx.Variables["x"] = b;
            fx.Compile();
            double b_fpt = fx.Calculate() * fddx.Calculate();

            double fixedPoint = a_fpt > 0 ? a : b;

            fx.Variables["x"] = fixedPoint;
            fdx.Variables["x"] = fixedPoint;
            double xn = fixedPoint - fx.Calculate()/fdx.Calculate();
            count = 0;
            while ((xn - fixedPoint) > eps)
            {
                fixedPoint = xn;

                fx.Variables["x"] = xn;
                fdx.Variables["x"] = xn;

                xn = fixedPoint - fx.Calculate() / fdx.Calculate();
                ++count;
            }

            return xn.ToString();
        }
开发者ID:osst,项目名称:University,代码行数:40,代码来源:Form1.cs


注:本文中的Parser.Calculate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。