Hi everyone,
I know this is a self-explaining error. I know it is usually caused by:
1) Passing a function more input arguments than it expected to receive, perhaps by passing a list of inputs rather than a vector of inputs, or have tried to obtain two outputs from a function that only returns one.
2) You have multiple functions with the same name. etc.
But I think all my inputs the function in line 117 are requred, yet I still get an error message:
Error using fzero (line 306)
FZERO cannot continue because user-supplied function_handle ==> @(pH)HionpH(pH,b) failed with the error below.
Too many input arguments.
Error in SlurryCase10Feb2019>kinetics (line 117)
pH = fzero(@(pH)HionpH(pH,b),pH1);
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in SlurryCase10Feb2019 (line 73)
[b]=lsqcurvefit(@kinetics,b0,tdata,ydata);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
What can I change, on the attached code, to solve this problem?

댓글 수: 2

BERGHOUT Tarek
BERGHOUT Tarek 2019년 2월 10일
send me the main program and subprogmes in rar file , and i will help you
Dursman Mchabe
Dursman Mchabe 2019년 2월 12일
Thanks a lot Berghout. Apology for the delayed response. My PC stopped working. To which email address must I send the file. It is actual a very small program. I have it in one script. Lines 82 to 180 are the main program. Sub-programes are the nested functions.

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

 채택된 답변

Stephen23
Stephen23 2019년 2월 10일
편집: Stephen23 2019년 2월 10일

1 개 추천

Everywhere you call function HionpH you call it with two input arguments, but you defined the actual function with just one input argument (thus the error):
function ph = HionpH (pH)
"What can I change, on the attached code, to solve this problem?"
There are two possible solutions:
  • only call HionpH with one input argument (matching how it is defined), or
  • change the definition to accept two input arguments, e.g.:
function ph = HionpH(pH,b)
and then you will have to decide what you want to do with that input (if anything).

댓글 수: 6

Dursman Mchabe
Dursman Mchabe 2019년 2월 12일
Thanks a lot Stephen. Apology for the delayed response. My PC stopped working.
I have just implemented your suggestion 1. It resolves the error, and gives another error:
Error using fzero (line 328)
Function value at starting guess must be finite and real.
Error in SlurryCase10Feb2019>SO2_OdeDriver (line 218)
pH = fzero(@(pH)HionpH(pH,b),pH_trial);
Error in SlurryCase10Feb2019>kinetics (line 164)
y = SO2_OdeDriver(y0,b);
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in SlurryCase10Feb2019 (line 73)
[b]=lsqcurvefit(@kinetics,b0,tdata,ydata);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
>>
Dursman Mchabe
Dursman Mchabe 2019년 2월 12일
To solve the new error (above), I usually find the zero of the equation in this case @HionpH gave a pH value of 6.6379. Which I inturn use as the initial value. However, the error persist.
Set a breakpoint on the line where the error occurs then run your code. When you reach the breakpoint, evaluate your function at the starting guess.
HionpH(pH_trial, b)
My guess is that the result of that function evaluation is complex (taking the logarithm of a negative number, perhaps.) If that's the case, set another breakpoint inside HionpH and run that command again, working your way through line by line to figure out where the complex number in introduced and whether the command that introduced the complex number is doing what it should.
Dursman Mchabe
Dursman Mchabe 2019년 2월 12일
Thank you. I try that.
I have set a breakpoint on line 218, and I have used a starting guess of pH_trial of 6.6379, which is a zero of @HionpH. Strangely, I still get:
Error using fzero (line 328)
Function value at starting guess must be finite and real.
Error in SlurryCase10Feb2019>SO2_OdeDriver (line 218)
pH = fzero(@(pH)HionpH(pH,b),pH_trial);
Error in SlurryCase10Feb2019>kinetics (line 164)
y = SO2_OdeDriver(y0,b);
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in SlurryCase10Feb2019 (line 73)
[b]=lsqcurvefit(@kinetics,b0,tdata,ydata);
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.

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

추가 답변 (0개)

카테고리

질문:

2019년 2월 9일

댓글:

2019년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by