[Tutor] multiplication of polynomials in Python
Julieta Rangel
julieta_rangel@hotmail.com
Thu, 03 May 2001 02:59:00 -0500
I got the integration and differentiation programs to work. Right now I'm
working on multiplication of polynomials. This is what I have so far:
class Poly:
def __init__ ( self, v=m , c = [0]):
"""__init__():
Initializes a polynomial
variable is m
Default polynomial is zero"""
self.var = v
self.coef = c
self.deg = len(c)-1
self.length = len(c)
def __str__ (self):
"""__str__():
Converts a polynomial into a string"""
x = `self.coef[0]`
for i in range (1, self.deg+1):
x = x + "+" +`self.coef[i]` + self.var + "^" + `i`
return x
def Multiply(self):
"""Input: two instances of a polynomial
Output: a polynomial that is the product of the input polynomials
Side Effects: None"""
coef=[0]
coef2=[0]
self.deg = self.deg +1
for i in range(0,self.deg +1):
coef.append(
m = input('Enter the variable for polynomial1')
degree = input('Enter the degree of polynomial 1')
coef=[]
for i in range (0,degree + 1):
coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i)
coef.append(coefficient)
m = input('Enter the variable for polynomial 2')
degree = input('Enter the degree of polynomial 2')
coef2=[]
for i in range (0,degree + 1):
coefficient = input('Enter the coefficient for %s \n ^ %i ? ' %(m,i)
coef.append(coefficient)
Am I headed in the right direction? What do you think about what I have so
far? I'm trying to come up with the definition of multiply, but I'm stuck.
Can anyone help? If you have any comments or suggestions I'm all ears. By
the way, thank you everyone for all the help I've received from all of you.
Eventhough I still have a VERY LONG way to go, I feel I've learned so much
from you. Thank you for sharing your knowledge :)
Julieta
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com