Convolution of many vectors
조회 수: 7 (최근 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!