Estimation of parameters for curvefit using lsqcurvefit

5 次查看(过去 30 天)
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

回答(1 个)

Alan Weiss
Alan Weiss 2018-12-5
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Applications 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by