Convolution of many vectors
15 ビュー (過去 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!