Is there any build in function to perform polynomials multiplication?

2 visualizaciones (últimos 30 días)
Hi,
I try to find a build in function that satisfy the following:
(x1,y1) , (x2,y2)
result in:
( 0 , (x1*x2) , (x1*y2) + (y1*x2) , (y1*y2) )
I did it using while loop but it is useless! it take to long time : (
Thank you
  2 comentarios
Jan
Jan el 9 de Nov. de 2014
Claiming that the loop takes too long is not useful, when you do not post the code. Perhaps you did only forget to pre-allocate the result. In addition it is not clear if "x1" and "x2" are two variables with inconvenient names or the elements of a vector. The less the readers have to guess, the more useful will be the answers.
Abdulatif Alabdulatif
Abdulatif Alabdulatif el 10 de Nov. de 2014
This is the code:
vector1 = [232,334];
vector2 = [121,523];
M = sym(1000000000000);
A1 = length(vector1);
A2 = length(vector2);
A3 = length(vector1)+ length(vector2);
result = sym(zeros(1,A3));
mult=sym(0);
index=0;
% Set the first value of result vector to (0)
result(1,i) = 0;
% perform polynomials multiplication
i=1;
j=1;
while i < A1+1
while j < A2+1
index = i + j;
mult = sym((vector1(1,i) * vector2(1,j)));
mult = sym(rem(mult,M));
result(1,index) = result(1,index) + mult;
j=j+1;
end
j=1;
i = i+1;
end
produce:
result = [0, x1, x2, x3], where x1,x2 and x3 are variables.
As I implement clustering algorithm, I have to run this code around 4000 times which takes long time.
Sorry for inconvenient explanation!

Iniciar sesión para comentar.

Respuesta aceptada

Rick Rosson
Rick Rosson el 9 de Nov. de 2014
u = [ x1 ; y1 ];
v = [ x2 ; y2 ];
z = conv(u,v);

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by