public string ExampleCalculation()
        {
            double h = 0.002, sum = 0, I;

            CalculationEngine calculation = new CalculationEngine();

            if (!ExpressionChanges.Check_string(expression))
            {
                return("error");
            }
            if (ExpressionChanges.IsEmpty(botLim) || ExpressionChanges.IsEmpty(upperLim))
            {
                return("error_Lim");
            }

            if (Double.Parse(botLim) > Double.Parse(upperLim))
            {
                return("error_Lim");
            }

            try
            {
                for (double Xi = Convert.ToDouble(botLim) + h; Xi < Convert.ToDouble(upperLim); Xi = Xi + h)
                {
                    I = 0;

                    calculation.Variables["x"] = Xi;
                    I += (double)calculation.Evaluate(expression);
                    calculation.Variables["x"] = Xi - h;
                    I += (double)calculation.Evaluate(expression);
                    calculation.Variables["x"] = Xi - h / 2;
                    I   += 4 * (double)calculation.Evaluate(expression);
                    sum += I;
                }
            }
            catch (Exception e)
            {
                return("error");
            }

            double res = h / 6 * sum;

            if (Double.IsNaN(res))
            {
                return("error_ODZ");
            }

            return(res.ToString());
        }
Beispiel #2
0
        static object CountIf(CalculationEngine ce, List <Expression> p)
        {
            var cnt   = 0.0;
            var ienum = p[0] as IEnumerable;

            if (ienum != null)
            {
                var crit = (string)p[1].Evaluate();
                foreach (var value in ienum)
                {
                    if (!IsBlank(value))
                    {
                        var exp = string.Format("{0}{1}", value, crit);
                        if ((bool)ce.Evaluate(exp))
                        {
                            cnt++;
                        }
                    }
                }
            }

            return(cnt);
        }