Groophy.Math.Math.Sigma(new GValue("2"), new GValue("5"), "n*2");
(2*2(4) + 3*2(6) + 4*2(8))-> 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /// <summary> /// https://groophy-inc.github.io/sigma /// </summary> /// <param name="n"></param> /// <param name="to"></param> /// <param name="formula"></param> /// <returns></returns> public static GValue Sigma(GValue n, GValue to, string formula) { double result = 0; MathParser parser = new MathParser(); parser.LocalVariables.Add("n", 0); for (int i = n.get_Int; i < to.get_Int;i++ ) { parser.LocalVariables["n"] = i; result += parser.Parse(formula); } return new GValue((result.ToString())); } |
Copyright © Groophy.Inc ' Batch-Man