FZERO requires at least two input arguments

11 Ansichten (letzte 30 Tage)
Andreas Nathaniel
Andreas Nathaniel am 28 Mai 2020
Kommentiert: Steven Lord am 28 Mai 2020
Hey, I need help
function [y,fx,x] = solveNadiabxy(al,bt,ga,kc,yc)
warning off; midtol = 10^-13;
fzero ltol = 10^-14; mid = 1;
change if critical options = optimset('dis',[].'tolx', ltol);
x0 = fzero(@Nadiab,0,options,al,bt,ga,kc,yc);
x1 = fzero(@Nadiab,1,options,al,bt,ga,kc,yc);
if abs(x0 - x1) > 10^-10
check with graph xmid = fzero(@Nadiab,[1.01*x0,0.99*x1], options,al,bt,ga,kc,yc);
else, xmid = (x0+x1)/2;
end
x = [x0 xmid x1];
y = sort ((1+kc*yc + bt*(1-x))/(1+kc));
fx = Nadiab (x,al,bt,ga,kc,yc);
function f = Nadiab(x,al,bt,ga,kc,yc)
f = 1 - x - al*exp(-ga*(1+kc)./(1+kc*yc + bt *(1 - x))) .* x;
this is the code that i used, but everytime want to solve the problem it came Fzero requires arguments

Akzeptierte Antwort

John D'Errico
John D'Errico am 28 Mai 2020
However you got the code you wrote, much of it is not valid syntax in MATLAB.
This line, for example:
fzero ltol = 10^-14; mid = 1;
That is likely where the error message comes from about input arguments to fzero. For example, if I try to execute that line, I get this error:
fzero ltol = 10^-14; mid = 1;
Error using fzero (line 133)
FZERO accepts inputs only of data type double.
Which happens to be what you saw.
As well, several of the lines you have in that code are NOT valid MATLAB syntax. They appear to be comments. Most likely you have mistyped things, and forgotten the % symbols at the beginning of the line. If that was truly exactly what was found in that text, then there is a problem in the text. My guess is that is not the case, but I cannot know.
If you don't recognize MATLAB syntax at all, and are just trying to execute code fragments however you find them, you might want to start by learning at least a little bit about MATLAB. Consider the MATLAB Onramp course.

Weitere Antworten (2)

KSSV
KSSV am 28 Mai 2020
You have to provide inputs to the function. Save those functions in a file, in a folder.
al = give your value ;
bt = give your value ;
ga = give your value ;
kc = give your value ;
yc = give your value ;
[y,fx,x] = solveNadiabxy(al,bt,ga,kc,yc) ;
  9 Kommentare
Andreas Nathaniel
Andreas Nathaniel am 28 Mai 2020
al = 180000 ;
bt = 1 ;
ga = 15 ;
kc = 1 ;
yc = 1 ;
[y,fx,x] = solveNadiabxy(al,bt,ga,kc,yc) ;
Andreas Nathaniel
Andreas Nathaniel am 28 Mai 2020
This code came from the Numerical Techniques for Chemical and Biological Engineers Using MATLAB book

Melden Sie sich an, um zu kommentieren.


Steven Lord
Steven Lord am 28 Mai 2020
Bearbeitet: Steven Lord am 28 Mai 2020
I have a number of pieces of feedback on this code. It looks like it was written for an older version of MATLAB and was copied incorrectly from the textbook.
function [y,fx,x] = solveNadiabxy(al,bt,ga,kc,yc)
warning off; midtol = 10^-13;
Don't turn off all warnings, especially if you never turn them back on. MATLAB can help you understand where you may be doing something you shouldn't be, but not if you tell it to shut up.
fzero ltol = 10^-14; mid = 1;
This is almost certainly not what you wanted to write here. This calls fzero with three pieces of text as inputs.
change if critical options = optimset('dis',[].'tolx', ltol);
This attempts to call a function named change with several pieces of text as input. Perhaps the "change if critical" part was supposed to be a comment and the optimset call was supposed to be on the next line, like this?
% This section added by Steve Lord, not part of the original code
% change if critical
options = optimset('dis', [], 'tolx', ltol);
x0 = fzero(@Nadiab,0,options,al,bt,ga,kc,yc);
x1 = fzero(@Nadiab,1,options,al,bt,ga,kc,yc);
While this works, it's an older syntax for fzero. That syntax is supported for backwards compatibility and is no longer documented. Instead you should use one of the techniques given on this documentation page to pass the additional parameters into your Nadiab function.
if abs(x0 - x1) > 10^-10
check with graph xmid = fzero(@Nadiab,[1.01*x0,0.99*x1], options,al,bt,ga,kc,yc);
This tries to call a function named check with several pieces of text as input. Like the "change if critical" section, it looks like the first part is supposed to be a comment. It also uses the older fzero syntax.
  2 Kommentare
Andreas Nathaniel
Andreas Nathaniel am 28 Mai 2020
can i get the newest one and the correct one?
Steven Lord
Steven Lord am 28 Mai 2020
The newest what? The newer syntax for fzero? See that documentation page I linked for some of the currently recommended ways to pass additional parameters into the function you pass into fzero.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by