[Tutor] rational number representation in Python

Julieta Rangel julieta_rangel@hotmail.com
Wed, 02 May 2001 11:58:22 -0500


To integrate a polynomial, say 3x^2+7x+4, we have to add one to the exponent 
and then divide the coefficient by this result.  For example, in our 
polynomial above, we would have to add 1 to our exponent so that we get 
3.Then we divide our coefficient by this result (3/3=1), so our new 
coefficient is going to be one.  We do the same thing to the next term; we 
add one to our exponent, which will give us 2, and then divide the 
coefficient by 2 (7/2).  And finally we add one to the exponent of x^0, so 
this will give us 1 and we divide 4 by 1.  So that we get apolynomial 
looking like this: (3/3)x^3 + (7/2)x^2 + (4/1)x  or better yet, x^3 + 
(7/2)x^2 + 4x.  My problem is, once I know the degree of my polynomial and 
the coefficients of my polynomial, how can I do all these operations?  My 
problem is representing rational numbers, ie,(7/2).  Because my result of 
this division is not an integer, I don't want Python to divide.  I want 
(3/3) to be divided, (4/1) to be divided, but I want (7/2) to be left alone. 
  How can I do this?  Can anyone help?

Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com