Hi to all,

I'm solving some numerical analiyse problems in C#.
Is there any C# implemented function similar to eval() in Matlab?
So, user type the function that he wants to evaluate in text box, and
eval(String s, double x) evaluate value of that function with argument x.
For example, if user wants to evaluate function y=x*x+6*x+12+sin(90) for x=6,
eval("sin(x)+x*x+6*x+12", 6) returns double value of result of this function - 85.

I appreciate any kind of help.

Thanks in advance

You could have a look at 3 code snippets I wrote which together form a console calculator. It accepts variables and expressions defined with these variables. As an example I also implemented the the sqrt function to be used in expressions. I suppose it can easily be adapted to make an eval method for the kind of functions you want.
http://www.daniweb.com/code/snippet217185.html
http://www.daniweb.com/code/snippet217186.html
http://www.daniweb.com/code/snippet217187.html
Succes!

You could have a look at 3 code snippets I wrote which together form a console calculator. It accepts variables and expressions defined with these variables. As an example I also implemented the the sqrt function to be used in expressions. I suppose it can easily be adapted to make an eval method for the kind of functions you want.
http://www.daniweb.com/code/snippet217185.html
http://www.daniweb.com/code/snippet217186.html
http://www.daniweb.com/code/snippet217187.html
Succes!

Great!!!

Congratulations for this code, it's fantastic...this should help me very much...all I have to do is to add some math functions (sin, exp, cos...)...

thank you very much!

Glad to be of help, so unless you have some more questions about this code, could we call this thread solved?
I looked over this code recently and I noticed I left some error messages in my native language, but it should cause not much problems to translate them.

yes, we can call this tread solved...thanks once again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.