Convert String to Function

As many of you have experienced, the maplet MathMLEditor, has some problem when it comes to interpret correctly the typing functions, even some functions with the help of the palette.

I was trying to input this function : sin(4*x)+cos(2*x) but after moving form the unknown tag _XML_ error, I end up with misinterpretations of this function, to things like  4*sin(x)+cos(2*x).

So, the comments in this blog tells that the better solution is to use a TextField to get the input function, but now I face this problem

f := Get('txtFunction');
 

makes f an string with the value "sin(4*x)+cos(2*x)" so I can manipulate it, like calculating the derivative, or evaluating it.

Anybody can tell me how can I do this?

Thanks

Comments

Use parse

str := "sin(4*x)+cos(2*x)";
                                      str := "sin(4*x)+cos(2*x)"

y := parse(str);
                                       y := sin(4 x) + cos(2 x)

diff(y,x);
                                        4 cos(4 x) - 2 sin(2 x)
 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}