Algorithm to polynomial multiplication

asked 2018-04-25 01:02:57 -0600

gab123 gravatar image

I need to create algorithm to polynomial multiplication , but I don't know how to do it. Please for help.

edit retag flag offensive close merge delete

Comments

1

Some questions:

  1. How is that related to SageMath?
  2. What have you tried so far?
  3. Did you notice that SageMath already has algorithms for polynomial multiplication?
  4. Is that homework?
B r u n o gravatar imageB r u n o ( 2018-04-25 08:05:54 -0600 )edit

I know that SageMath has algorithms for polynomial multiplication, but I must write it myself. Yes, it is my homework I wrote something like this, but in the end should be showed polynomial, not only factors. I don't know how to do it. Could you help me? Please

W1=[1,2,3,4] W2=[5,4,3,2,1] W3=[]

for i in range(0,len(W1)+len(W2)-1): W3.append(0)

for i in range(0,len(W1)): for j in range(0,len(W2)): W3[i+j]=W3[i+j]+W1[i]*W2[j]

print(W3)

gab123 gravatar imagegab123 ( 2018-04-25 12:14:18 -0600 )edit

Your algorithm is fine for multiplying the polynomials. What you get is the list of coefficients. (I don't know what you mean by "factors".) If you want a polynomial from this list, you have to build a polynomial ring and get the polynomial from the list of coefficients in the following way:

sage: R = PolynomialRing(ZZ, 'x') 
sage: L = [1, 2, 3, 4, 5]
sage: p = R(L)
sage: p
5*x^4 + 4*x^3 + 3*x^2 + 2*x + 1
B r u n o gravatar imageB r u n o ( 2018-04-27 05:05:40 -0600 )edit