ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
[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,&nbsp;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.&nbsp; Lets say the user wants to
 multiply two polynomials.&nbsp; 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,&nbsp; in this case the compu
ter would have to ask the user to enter the coefficient of&nbsp; x^3, x^2, x, and c and then
 the coefficients of the second polynomial.&nbsp; Should I have the computer create two list
s for each polynomial?&nbsp; In one list I would store all the coefficients and in another t
he exponents of the expression.&nbsp; I'm assuming that if I have two lists for each polynom
ial, I could do the operations required.&nbsp; 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].&nbsp;I would then have the first element in L1 
times each element in L2, so that I get&nbsp;list 5&nbsp;[2,0,2]</DIV> 
<DIV> and 1st element in L3 + each element in L4, so that I get list 6 [5,4,3].&nbsp; 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].&nbsp; 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].&nbsp; I would then take the numbers from my lists and have the computer write th
e coefficients along with the exponents:&nbsp; 2x^5 + 0x^4 + 2x^3 + x^4 +0x^3+x^2+3x^3+0x^2 
+3x+ 2x^2+0x+2.&nbsp;&nbsp;&nbsp; I would then have to get rid of those terms with zero coef
ficients and combine like terms.&nbsp; Is this crazy or what?&nbsp; How could I accomplish t
his?&nbsp; 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.&nbsp; Can you help?</DIV> 
<DIV> &nbsp;</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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved