how to parse standard algebraic notation

wxjmfauth at gmail.com wxjmfauth at gmail.com
Wed Oct 1 10:08:57 CEST 2014


Le mardi 30 septembre 2014 22:53:22 UTC+2, math math a écrit :
> Hi,
> 
> 
> 
> I am trying to learn Python while solving exercises. 
> 
> 
> 
> I want to basically write a program that inputs a polynomial in standard algebraic notation and outputs its derivative.
> 
> 
> 
> I know that I need to get the exponent somehow, but I am not sure how to accomplish this in python (3.3)
> 
> 
> 
> Do you have any ideas or suggestions? I don't want to use existing modules as this is meant to be a didactic experience.
> 
> 

I would
- stick with a single algebric notation
- stick with a "variable"
- toy with string manipulations

Suggestion:
- split your polynomial in monomials
- extract the coefficients
- recompose the derivative

Eg, Transform
f(x) = azx**3 + 3x**2 +2y -x(3-2)
into
f'(x) = 3azx**2 + 6x - (3-2)

trap: 3*2 -> 6!

Simpler way
f(x) = a*z*x**3 + 3*x**2 +2*y -x*(3-2)
into
f'(x) = 3*a*z*x**2 + 3*2*x - (3-2)

jmf




More information about the Python-list mailing list