[Tutor] Multiplication of polynomials
by Julieta Rangel other posts by this author
Apr 29 2001 4:48PM messages near this date
Re: [Tutor] Help with saving data
|
Re: [Tutor] Multiplication of polynomials
<html> <DIV>If I want to write a program that multiplies polynomials, just to show you h
ow illiterate I am at computer programming, this is what I would do: I would need the user t
o enter the amount of polynomials that will be multiplying. Lets say the user wants to
multiply two polynomials. Once the user enters the amount of polynomials that will be
multiplying, the computer would have to ask the degree of the polynomials, say the first po
lynomial is of third degree and the second is a second degree polynomial (2x^3 + x^2 + 3x +
2) * (x^2 + 1)Once the person enters the degree of the polynomials, the computer would have
to ask the coefficient of each of the terms of the polynomials, in this case the compu
ter would have to ask the user to enter the coefficient of x^3, x^2, x, and c and then
the coefficients of the second polynomial. Should I have the computer create two list
s for each polynomial? In one list I would store all the coefficients and in another t
he exponents of the expression. I'm assuming that if I have two lists for each polynom
ial, I could do the operations required. Based on the polynomials I have, the lists of
coefficients would look like (L1) [2,1,3,2] and (L2)[1,0,1] and my lists of exponents would
look like (L 3) [3,2,1,0] and (L 4)[2,1,0]. I would then have the first element in L1
times each element in L2, so that I get list 5 [2,0,2]</DIV>
<DIV> and 1st element in L3 + each element in L4, so that I get list 6 [5,4,3]. Then I
would have the 2nd element in L1 times each element in L2 so that I get another list [1,0,1
] and also have the 2nd element in L3 + each element in L4, so that I get [4,3,2]. Thi
s would go on for each element and I would end up with 4 more lists [3,0,3], [3,2,1], [2,0,2
], [2,1,0]. I would then take the numbers from my lists and have the computer write th
e coefficients along with the exponents: 2x^5 + 0x^4 + 2x^3 + x^4 +0x^3+x^2+3x^3+0x^2
+3x+ 2x^2+0x+2. I would then have to get rid of those terms with zero coef
ficients and combine like terms. Is this crazy or what? How could I accomplish t
his? Like I told you before, this is all new to me, but I'm really interested in findi
ng out how this complex task can be accomplished in Python. Can you help?</DIV>
<DIV> </DIV>
<DIV> Julieta</DIV><br clear=all><hr>Get your FREE download of MSN Explorer at <a href="http:
//explorer.msn.com"> http://explorer.msn.com</a><br></p></html>
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Julieta Rangel
Remco Gerlich
Benoit Dupire
Sheila King
|