Feb 27, 2012 at 2:59 PM
Edited Feb 27, 2012 at 2:59 PM

I found this page helpful:
http://www.cdrnet.net/projects/nmath/symbolics/classic/mathwithdotnet.asp
Below is my attempt to a simple expression, and partial differentiation:
Parser p = new Parser();
p.Provider = (ITreeTokenProvider)new InfixTokenizer();
IScalarExpression exp = p.Parse("20*ln(x/y)") as IScalarExpression;
//double d = exp.Calculate();
VariableManager man = new VariableManager(exp.Context);
exp.CollectVariables(man, true);
ScalarExpressionVariable x = man.GetCreateVariable("x") as ScalarExpressionVariable;
ScalarExpressionVariable y = man.GetCreateVariable("y") as ScalarExpressionVariable;
IScalarExpression dxExp = exp.Differentiate(x);
IScalarExpression dyExp = exp.Differentiate(y);
x.Value = new ScalarExpressionValue(x.Context, 1);
y.Value = new ScalarExpressionValue(y.Context, 2);
exp.Calculate();
This successfully computes the partial derivatives, I double checked with MATLAB.
However, my problem is with numerically calculating the expressions.
THe example in the page above does not seem to work.
Perhaps it was for a different version o the software,
but the latest version gives a "CalcNotConstantException" at "exp.Calculate()"
I am yet to find a solution...If you find one please inform me :)
