load("nonlsqfitting.mat");
Hreal=interp1(fq,Y(:,1),ft,"linear","extrap");
Himag=interp1(fq,Y(:,2),ft,"linear","extrap");
cofInit=Init(ydata2,2*pi*ft);
conditionNum = 6.1543e+07
options = optimoptions('lsqcurvefit','MaxIter',inf,'MaxFunEvals',inf,...
'OptimalityTol',tol,'StepTol',tol,'FunctionTol',tol);
[cof,resnorm,residuals,exitflag,output] = ...
lsqcurvefit(@OBJrealimag,cofInit,2*pi*ft,ydata2,[],[],options);
Local minimum possible.
lsqcurvefit stopped because the final change in the sum of squares relative to
its initial value is less than the value of the function tolerance.
yy=OBJrealimag(cof,2*pi*ft);
semilogx(fq,Y(:,1),'k-');
plot(ft,Hreal,'r.',ft,yy(:,1),'bo');
legend('original real part','selected data','real part after fitting',Location='best')
plot(ft,Himag,'r.',ft,yy(:,2),'bo');
legend('original imaginary part','selected data','imaginary part after fitting',Location='best')
set(gca,'fontsize',18); set(gcf,'Position',gcf().Position.*[1,1,1.5,1.5])
[cofInit,cof]
ans =
1.0e+06 *
-0.0196 -0.0225
-0.0047 -0.0054
-0.0014 -0.0016
-0.0001 -0.0001
-0.0000 -0.0000
-0.1353 -0.1573
-1.4303 -1.6367
-0.4164 -0.4827
-0.0433 -0.0466
-0.0047 -0.0054
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
function T=Init(ydata2,w)
function yout=OBJrealimag(T,w)
H=polyval(p,s)./polyval([1,q],s);
yout=[real(H).',imag(H).'];