I get the wrong polyfit
5 views (last 30 days)
Show older comments
jiang tao
on 11 May 2018
Commented: Walter Roberson
on 11 May 2018
ftz = [1.4846i 1.1582i];
P_pie=poly(ftz);%roots=ftz
for j=-2:0.01:2
k=floor(((j+2)/0.01)+1);
P_pie_subs(k)=polyval(P_pie,j*1i);
P_subs(k)=P_pie_subs(k)/(2*sqrt(2));
end
x=(-2:0.01:2);
x=x*1i;
P=polyfit(x,P_subs,2);
roots(P)
% ans =
% 0.115192576001519 + 1.337122816059961i
% -0.115192576001520 + 1.337122816059962i
0 Comments
Accepted Answer
Walter Roberson
on 11 May 2018
ftz = [1.4846i 1.1582i];
P_pie=poly(ftz);%roots=ftz
jvals = -2:0.01:2;
for jidx = 1 : length(jvals)
j = jvals(jidx);
P_pie_subs(jidx)=polyval(P_pie,j*1i);
P_subs(jidx)=P_pie_subs(jidx)/(2*sqrt(2));
end
x=(-2:0.01:2);
x=x*1i;
P=polyfit(x,P_subs,2);
roots(P)
You forgot to take into account that binary floating point does not have an exact representation of 0.01, so your j values might not be exact multiples of 0.01 and floor() might get you a different index than you expect.
2 Comments
Walter Roberson
on 11 May 2018
If you had used round() instead of floor() you probably would have gotten what you wanted.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!