How to use lsqcurvefit to estimate parameters while using fsolve to solve an equation

조회 수: 1 (최근 30일)
Hi ebveryone,
On the attached code I am trying to use lsqcurvefit to estimate the following constants:
% Constants
KSO2 = Constant(1);
KHSO3 = Constant(2);
KCO2 = Constant(3);
KHCO3 = Constant(4);
Kw = Constant(5);
whilst using fsolve to solve an equation. Some I get an error message:
Error using pHCalcFeb25>pHCalculation
Too many output arguments.
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in pHCalcFeb25 (line 67)
Constant=lsqcurvefit(@pHCalculation,Constant0,t,pH);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
>>
How can I resolve this error. Please help

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 25일
Your function calculates ph as a vector of 31 values. However, your function is declared as if it has no return values at all. At the very least you need to change your function declaration to return ph .
It was easier to debug by splitting your function into two files, which I attach.
  댓글 수: 7
Dursman Mchabe
Dursman Mchabe 2019년 2월 25일
편집: Dursman Mchabe 2019년 2월 25일
I Actually need a tv of length 31. I will try:
or
tv = linspace(min(t), max(t),31);
Dursman Mchabe
Dursman Mchabe 2019년 2월 25일
Thank you , thank you , thank you. It works perfectly.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by