lsqcurvefit and anonymous function error
Mostra commenti meno recenti
I'm trying to use lsqcurvefit with an anonymous function within the script to determine the best fit for a hyperbolic tangent function. However, I keep receiving the following error as outlined by the exception variable:
'Objective function is returning undefined values at initial point. lsqcurvefit cannot continue.'
Here is the code:
% Estimate hyperbolic tangent parameters using least squares curve fit.
xo = [ 15; 20; 15 ]; % initial guess of tangent curve parameters.
lb = [ 16; 0; 0 ]; ub = [ 17; 40; 40 ]; % Bounds for the parameters
d = 0:0.1:65;
hyper = @( c, rkm ) c( 1 ).*( 1 - tanh( ( rkm - c( 2 ) ./ c( 3 ) ) ) );
for n = 1:2%size( sal, 1 )
try
% Fit the hyperbolic tangent parameters using the least squares curve fit.
[ param, resnorm ] = lsqcurvefit( hyper, xo, rkm, sal(n,:), lb, ub );
BSo(n) = param(1);
Bxc(n) = param(2);
BxL(n) = param(3);
catch exception2
continue
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Nonlinear Least Squares (Curve Fitting) in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!