Connecting Tech Pros Worldwide Help | Site Map

turning a string into an equation

Newbie
 
Join Date: May 2009
Posts: 16
#1: Oct 3 '09
so i have an entry frame where i want to input an equation, and i need to turn the string into an actual equation in terms of x. so that i can plot it on a canvas.
i already know how to make the entry frame, and how to extract the string equation that was inputed.
the only problem i'm having is converting it into an actual equation.
e.g.
the string input is 'sin(x)'
and i want to turn it into sin(x)
x is defined by another entry frame which will indicate the number of steps between two boundaries.
say the boundary was [-10, 10]
and the number of steps was set to 40
therefore x will be equal to [-10:0.5:10]

so i was thinking that i should define the values for x first using a simple loop, and then convert 'sin(x)' into an equation.

everything is pretty easy besides the conversion.
any help is appreciated
thanks
phoenix1990
Member
 
Join Date: Nov 2008
Posts: 43
#2: Oct 5 '09

re: turning a string into an equation


Actually everything including the conversion is pretty easy. This is one of python's strengths! Check out the eval() command.
Newbie
 
Join Date: May 2009
Posts: 16
#3: Oct 5 '09

re: turning a string into an equation


thanks for the help Glenton.
it worked like a charm.
Reply