Is there any build in function to perform polynomials multiplication?

2 次查看(过去 30 天)
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 个评论
Jan
Jan 2014-11-9
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
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!

请先登录,再进行评论。

采纳的回答

Rick Rosson
Rick Rosson 2014-11-9
u = [ x1 ; y1 ];
v = [ x2 ; y2 ];
z = conv(u,v);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by