Estimation of parameters for curvefit using lsqcurvefit

조회 수: 5 (최근 30일)
Dursman Mchabe
Dursman Mchabe 2018년 12월 5일
댓글: Maryam Alyahyai 2022년 4월 12일
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
Maryam Alyahyai
Maryam Alyahyai 2022년 4월 12일
Done. I've posted it as a new question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by