Evaluation-Interpolation using FFT algorithm
显示 更早的评论
I'm trying to develop a FFT algorithm for evaluation-interpolation of polynomials.
I tried the simple function
where the coefficients are expressed as
but only the DFT seems to work. I've spent quite some time on this and I can't make it work. Any suggestions?
but only the DFT seems to work. I've spent quite some time on this and I can't make it work. Any suggestions?f = @(x) x^3;
Pf = [1 , 0 , 0 , 0];
yf = FFT(Pf,1);
y = FFT(yf,2)
function y = FFT(P,k)
% k = 1 -> DFT
% k = 2 -> IDFT
N = length(P);
omega = exp(2*pi*1i/N);
if k == 1
l = 1;
p = 1;
elseif k == 2
l = 1/N;
p = -1;
end
if N == 1
y = P;
else
n = N/2;
P_e = P(2:2:end);
P_o = P(1:2:end);
y_e = FFT(P_e,k);
y_o = FFT(P_o,k);
y = zeros(N,1);
for j = 1 : N/2
y(j) = y_e(j) + (l*omega^(p*(j-1)))*y_o(j);
y(j+n) = y_e(j) - (l*omega^(p*(j-1)))*y_o(j);
end
end
end
1 个评论
chicken vector
2020-12-22
编辑:chicken vector
2020-12-22
回答(1 个)
Matt J
2020-12-22
0 个投票
A highly impractical thing to do. If you know the coefficients of the polynomial, you should just use polyval().
However, if you must use FFT interpolation, then interpft() will readily do it,
3 个评论
chicken vector
2020-12-22
编辑:chicken vector
2020-12-22
Finding the roots of a 15th order polynomial can be highly unstable numerically, e.g.,
rTrue=sort((rand(1,15))*5);
coeffsTrue=poly(rTrue), %true coefficients
coeffs=coeffsTrue+[0,randn(1,15)]*1e-6*max(coeffsTrue), %add small errors to coefficients
rTrue, %true roots
r=sort(real( roots(coeffs) )).' %calculated roots
chicken vector
2020-12-22
类别
在 帮助中心 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
