This project has moved. For the latest updates, please go here.

Symbolic math support

Feb 14, 2012 at 5:33 AM

Hello,

After reviewing the Math.NET website, I see that there appear to be three different libraries that offer symbolic math support: Classic, Yttrium, and Palladium. I'm not sure which one to go with. :-) Are there any tutorials available for any of these?

Are any of these based on the ideas used in SymbolicC++ or GiNaC?

Thanks for any pointers or hints.

Ed

Feb 14, 2012 at 5:53 AM

By the way, I'm looking to do simple stuff like:

var x = Symbol("x");

var y = Symbol("y");

var eq = y == 2*x + 10;

to, for example, setup an equation representing a line in terms of some symbols 'x' and 'y'. I'd also like to do basic differentiation on various expressions.

Feb 27, 2012 at 3:59 PM
Edited Feb 27, 2012 at 3: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 :)