Differential equations

Greg Ewing see_reply_address at something.invalid
Wed Dec 11 19:29:59 EST 2002


Michael Hudson wrote:

> 
> The hard part of stuff like this is parsing the string "2x^3+3x-10".
> If you can convince yourself you can live with Lisp's prefix notation,
> writing this sort of thing is dead easy in scheme or CL...


If you're willing to write your expression in a form
such as

   Sum(Pow(Prod(2,"x"),3),Prod(3,"x"),-10)

you could delegate the parsing problem to Python
by defining suitable classes Sum, Prod, etc.

Taking this a step further, with suitably clever
__add__ etc. methods you could probably reduce this
to something like

   x = Var("x")
   y = 2*x^3+3*x-10


Then it's simply a matter of giving each class an

appropriate differentiate() method. :-)

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list