Convolution of many vectors

16 visualizzazioni (ultimi 30 giorni)
Calle Swedhag
Calle Swedhag il 30 Nov 2016
Risposto: Chris Turnes il 5 Dic 2016
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.
  1 Commento
Calle Swedhag
Calle Swedhag il 30 Nov 2016
For the assignment, every coefficient vector corresponds to a simple quadratic polynomial.

Accedi per commentare.

Risposte (2)

Andrei Bobrov
Andrei Bobrov il 1 Dic 2016
Modificato: Andrei Bobrov il 1 Dic 2016
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)));

Chris Turnes
Chris Turnes il 5 Dic 2016
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;

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by