Why am I getting the same result as the Initial guess when using lsqnonlin?
Afficher commentaires plus anciens
Hello,
I am using the nonlinear least square function (lsqnonlin) to determine parameter values of power spectral density fitting curve, but it is always giving the same result with my initial guess. The number of parameters to be determine is 7 as shown in the program below;
clear
load LWAL
t=1:length(y);
z=fft(y);
pyy=z.*conj(z)/length(y);
f1=4*(0:fix(length(pyy)/2)-1)/length(pyy);
f1=1./f1;
pyy2=(1:fix(length(pyy)/2));
loglog(f1,pyy(1:fix(length(pyy)/2)),'linewidth',1.5),title('power spectral density'); grid on
pyy2=pyy2(2:32767);
f1=f1(2:32767);
fun=@(x) (x(1)*((f1.^2+x(2)*f1.^3+x(3))/(f1.^4+x(4)*f1.^3+x(5)*f1.^2+x(6)*f1+x(7)))-pyy2);
x0=[0.2476 -3.4562 5.4871 3.5951 5.2421 -1.0198 0.098];
options = optimoptions(@lsqnonlin,'Algorithm','levenberg-marquardt','checkgradients',true);
for i=1:50
x=lsqnonlin(fun,x0);
end
pyy=pyy(4:65535);
for nn=1:32766
y1(nn)=x(1)*(f1(nn).^2+x(2)*f1(nn).^3+x(3))/(f1(nn).^4+x(4)*f1(nn).^3+x(5)*f1(nn).^2+x(6)*f1(nn)+x(7));
end
f1=1./f1;
loglog(f1,pyy(1:fix(length(pyy)/2)),'linewidth',1.5),title('power spectral density');
hold on
loglog(f1,y1(1:fix(length(pyy)/2)),'linewidth',1.5),title('power spectral density')
xlabel('Spatial wavelength m^{-1}'),ylabel('PSD/(mm^2.m)');
grid on
3 commentaires
Ameer Hamza
le 29 Avr 2020
Why are you running lsqnonlin 50 times using the same initial guess? When I run you code, lsqnonlin does not give the same result as your initial guess.
Umar Faruk Aminu
le 29 Avr 2020
You're not storing the outputs on each iteration.
x = nan(50,7);
for i=1:50
x(i,:) =lsqnonlin(fun,x0);
end
Of course you'll have 50 of the same result since you're using the same initial guesses. Maybe you're intention is to jitter the initial guesses to ensure you've reached a global minima. That involves adding/subtracting a tiny bit from each initial guess on each iteration of the loop.
The first two parameters are different than you initial guesses but the others are not. That suggests that initial guesses 3:7 are already at a local (or global?) minima.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Surrogate Optimization dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
