Estimation of parameters for curvefit using lsqcurvefit

6 vues (au cours des 30 derniers jours)
Dursman Mchabe
Dursman Mchabe le 5 Déc 2018
Commenté : Maryam Alyahyai le 12 Avr 2022
Hi everyone,
On the attached script I am trying to use lsqcurvefit to estimate parameters x(1), x(2), x(3), x(4), x(5) and x(6). This is done in lines 480 to 488, and given as
x0=[8.825e-6;8.4e-3;2e-8;4.7e-3;8.4e-4;9.598e-4];
[x,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(Results,x0,Exp_Time,...
[Exp_SO2_g;Exp_CO2_g;Exp_S_total;Exp_C_total;Exp_CCaCO3;Exp_CCaSO3;Exp_pH;Exp_pH_Int]);
fprintf(1,'\tParameters:\n')
for k1 = 1:length(x)
fprintf(1, '\t\tx(%d) = %8.5f\n', k1, x(k1))
end
I have read/studied the lsqcurve documentation in
however, the examples and descriptions given there are too simplistic. I would like to ask for help on how best can i implement lsqcurvefit on my script.
The script run with initial values, however calculated values does not fit the experimental values yet.
Kind Regards
Dursman

Réponses (1)

Alan Weiss
Alan Weiss le 5 Déc 2018
Apparently, you are solving an ODE by forward Euler steps. Don't do that. It is both inaccurate and wasteful of computer time. I refer to these steps in your code:
dydt = odes (t, y0);
% integrate with explicit Euler
y = y0 + dydt' * Delt;
Instead, you should call ode45 to solve your ODE.
You also have many more global variables than you need, but that is a discussion for another time.
Now for the question you asked. I get an error when running your supplied code:
Error using lsqfcnchk (line 108)
FUN must be a function, a valid character vector expression, or an inline function object.
Error in lsqnsetup (line 46)
funfcn = lsqfcnchk(FUN,caller,lengthVarargin,funValCheck,flags.grad);
Error in lsqcurvefit (line 201)
lsqnsetup(FUN,xCurrent,LB,UB,options,defaultopt,allDefaultOpts, ...
Error in mytry (line 483)
[x,Rsdnrm,Rsd,ExFlg,OptmInfo,Lmda,Jmat]=lsqcurvefit(Results,x0,Exp_Time,...
Specifically, your Results argument is not a function handle. lsqcurvefit needs to be able to change the parameters and rerun your calculations to fit the function to the data. So I am not completely sure what you are trying to do, but you haven't supplied us with working code to check.
Have you seen the example Fit and Ordinary Differential Equation (ODE)? It is intended to guide you through using lsqcurvefit to fit an ODE.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  8 commentaires
Maryam Alyahyai
Maryam Alyahyai le 12 Avr 2022
Done. I've posted it as a new question.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Applications dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by