Convolution of many vectors
13 次查看(过去 30 天)
显示 更早的评论
I will try to explain my problem thoroughly. I have an input vector F that could be thousands of elements long. For this example lets say F is [1,2,3,4,5].
I then have a function that generates polynomial coefficients out of element k in F. The function could be
[k^2, 5*k, k+2]
for F(1) the polynomial coefficients are [1^2, 5*1, 1+2] and for F(2) it's [2^2, 5*2, 2+2] and so on. This I can accomplish with a loop. After generating polynomial coefficients for all elements k in F, I have to multiply the corresponding polynomials all together. Think of it like (1 + 5x + 3x^2)*(4 + 10x + 4x^2)*...*(F(5)^2, F(5)*5, F(5) + 2). I thought a convolution loop might work here, but I feel like it's a bit too complex for me to make one. Remember that in this example the number of elements in F was 5, but it might as well be thousands.
Thankful for any help I might get.
回答(2 个)
Andrei Bobrov
2016-12-1
编辑:Andrei Bobrov
2016-12-1
f = @(k)[k+2, 5*k, k.^2];
A = f((1:5)');
[m,n] = size(A);
B = zeros(1,m*(n-1)+1);
B(1:n) = A(1,:);
for ii = 1:m-1
B(1:n-ii+ii*n) = conv(B(1:ii*n-ii+1),A(ii+1,:));
end
x = [7,5];
out = polyval(B,x);
or
f = @(k)[k+2, 5*k, k.^2];
A = f((1:5)');
x =[7,5];
out = squeeze(prod(sum(A.*(reshape(x,1,1,[]).^(2:-1:0)),2)));
0 个评论
Chris Turnes
2016-12-5
You can use a fun trick here. Each of these polynomials is a quadratic, so you can find their roots easily enough:
F = F(:); % just in case F isn't a column...
rs = [(-5*F + sqrt((5*F).^2 - 4*(F+2).*(F.^2))) ./ (2*(F.^2)); ...
(-5*F - sqrt((5*F).^2 - 4*(F+2).*(F.^2))) ./ (2*(F.^2))];
Now you have all the roots for each polynomial, and when you multiply polynomials you just multiply their roots, so you can build the monic version of your final polynomial by just calling p=poly(rs). The last step is to factor in the leading coefficients by p = prod(F.^2)*p;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!