Math Expression¶
Load libs
In [1]:
#r "./dotnet-libs/Nequeo.Math.dll"
using Nequeo.Math;
using System;
using System.IO;
Create instance
Run expression
In [2]:
Nequeo.Math.MathGenerics<string> exp = new Nequeo.Math.MathGenerics<string>();
double result = exp.Expression<Double>("cos(x) * sin(x) * sqrt(x) * pi", 3.0, "x");
double result1 = exp.Expression<Double>("((34.8 * 23) * sqrt(9.0)) + pi");
Compute result
In [3]:
Console.WriteLine(result);
Console.WriteLine(result1);
-0.7602054794855984 2404.3415926535895
Run expression with variables
In [4]:
System.Collections.Generic.Dictionary<string, double> vars = new System.Collections.Generic.Dictionary<string, double>();
vars.Add("x", 2.7);
vars.Add("y", 5.7);
vars.Add("z", 5.7);
double result2 = exp.ExpressionMulti<Double>("2y^5 * 6x^2 * z * pi", vars);
Compute result
In [5]:
Console.WriteLine(result2);
9425573.428813294
Run expression with multi line, compute mean
In [6]:
double mean = exp.Expression<Double>(
" var x[25] := { " +
" 1, 2, 3, 4, 5, " +
" 6, 7, 8, 9, 10, " +
" 11, 12, 13, 14, 15, " +
" 16, 17, 18, 19, 20, " +
" 21, 22, 23, 24, 25 " +
" }; " +
" " +
" avg(x)");
Compute result
In [7]:
Console.WriteLine(mean);
13
Run expression with multi line, compute standard deviation
In [8]:
double standardDeviation = exp.Expression<Double>(
" var x[25] := { " +
" 1, 2, 3, 4, 5, " +
" 6, 7, 8, 9, 10, " +
" 11, 12, 13, 14, 15, " +
" 16, 17, 18, 19, 20, " +
" 21, 22, 23, 24, 25 " +
" }; " +
" " +
" sqrt(sum([x - avg(x)]^2) / x[]) ");
Compute result
In [9]:
Console.WriteLine(standardDeviation);
7.211102550927978
In [ ]: