Effacer les filtres
Effacer les filtres

Nonlinear regression using lsqcurvefit

2 vues (au cours des 30 derniers jours)
Jason Yee
Jason Yee le 4 Juil 2022
Commenté : Jason Yee le 6 Juil 2022
Here is my code, along with my error message.
T = V22050100Emat;
A = table2array(T);
f = A(389:402, 6);
y = A(389:402, 5);
% axis([0 1010 0 1.6E-7])
% hold on
plot(f,y,'ro')
title('Data points')
% hold off
F = @(x,f)(x(1)./2)*(sin(x(2).*pi/2)./(cosh(x(2).*log(2*pi*f*x(3).).)+cos(x(2).*pi/2)));
x0 = [1e-6 0.16 0.04];
size(f)
size(F)
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,f,y);
hold on
plot(f,F(x,f))
hold off
My error message
Error using lsqcurvefit
Function value and YDATA sizes are not equal.
Error in nonlinfit (line 20)
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,f,y);
I have also tried the 'fit' function with mixed results. Thank you.

Réponse acceptée

Torsten
Torsten le 4 Juil 2022
Modifié(e) : Torsten le 4 Juil 2022
F = @(x,f) x(1)/2 * sin(x(2)*pi/2)./(cosh(x(2)*log(2*pi*f*x(3)))+cos(x(2)*pi/2));
instead of
F = @(x,f)(x(1)./2)*(sin(x(2).*pi/2)./(cosh(x(2).*log(2*pi*f*x(3).).)+cos(x(2).*pi/2)));
What do you get if you type
size(f)
size(y)
?
Does f and/or y have Inf or NaN values ?
  5 commentaires
Torsten
Torsten le 5 Juil 2022
Modifié(e) : Torsten le 5 Juil 2022
Tighten the tolerances (FunctionTolerance and StepTolerance) in the options structure for lsqcurvefit.
And/or multiply F by a large number.
Jason Yee
Jason Yee le 6 Juil 2022
Thank you. This has solved my problem.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by