fzero function, not enough input arguments
9 views (last 30 days)
Show older comments
appleJuice
on 15 Nov 2016
Answered: Josilyn Dostal
on 22 Apr 2020
Hi!
I'm trying to calculate a simple function, separated in three parts (see code below). The function should be the input for a fzero function, where an extreme value for alpha is determined.
function time = uebung42(alpha)
x = 200;
y = 120;
yL = 70;
yW = y - yL;
vw = (7 * 1000) / 60 / 60;
vl = 3*vw;
term1 = (-yL * cos(alpha)) / (vl * (sin(alpha))^2);
term2 = yL * ((-sin(alpha))^2 - (cos(alpha))^2) * (x - (yL * cos(alpha)) / sin(alpha));
term3 = vw * (sin(alpha))^2 * sqrt( yW^2 + (x - (yL * cos(alpha)) / sin(alpha))^2);
time = term1 - ( term2 / term3);
end
Each individual term1-3 has a result and works fine, but when it try the fzero function, it gives me the following error message:
>> fun = @uebung42
fun =
@uebung42
>> alpha = fzero(uebung42,1)
Error using uebung42 (line 11)
Not enough input arguments.
Line 11 means the calculation for term1, but I just can't seem to find whats wrong with it. Any ideas?
0 Comments
Accepted Answer
More Answers (2)
Steven Lord
on 15 Nov 2016
This line of code:
>> alpha = fzero(uebung42,1)
tries to evaluate your uebung42 function with zero input arguments and pass the one output argument from that call into fzero as the first input argument. But your function requires you to specify one input argument. As Walter said, you've already created a function handle to your uebung42 function and stored it in the variable named fun. Use that as the first input argument to fzero.
0 Comments
Josilyn Dostal
on 22 Apr 2020
Im getting an error on line 39 that fzero does not have enough input arguments, what does this mean? any help would be greatly apprectiated!
P = 912; % mmHg or 1.2 atm
%Psat = 760; %
L0 = 100; % Moles liquid in the still initially
A = [6.90565 6.95464]; B=[1211.033 1344.8]; C=[220.79 219.482]; % Antoine Constants
x0 = [0.60 0.40]; % Initial liquid concentration xb = 60% xt = 40%
xf = [0.20 0.80]; % Final liquid concentration xb = 20% xt = 80%
BP = [80.1 110.6]; % DegC standard boiling points of b and t - temp at which vapor pressure equals atmospheric (760 mmHg)
db = 876; % kg/m^3
dt = 867; % kg/m^3
Tguess = 95.585;
xtspan = linspace(0.40,0.80,100);
[xt, L] = ode45(@Moles, xtspan, L0);
L = L(end);
fprintf('The amount of liquid remaining in the still when liquid mole fraction of toluene reaches 0.80 is %f moles', L);
% Vapor liquid equilibrium ratio, K
function Kt = EquilibriumRatio(Psatt)
Kt = Psatt/P;
end
% Toluene vapor pressure
function Psatt = VaporPressuret(T)
Psatt = 10^(6.9546-1344.8/(T+219.482));
end
% Benzene vapor pressure
function Psatb = VaporPressureb(T)
Psatb = 10^(6.9056-1211.033/(T+220.79));
end
% ODE
function dLdx = Moles(xt,L)
%T0 = 95.585;
%options = odeset('RelTol',1e-6,'AbsTol',1e-8);
T = fzero(@temp, 95.585);
Psatt = VaporPressuret(T);
Kt = EquilibriumRatio(Psatt);
dLdx = L/(xt*(Kt-1));
end
function Tempfun = temp(T,xt)
Psatt = VaporPressuret(T);
Psatb = VaporPressureb(T);
Tempfun = Psatt*xt + Psatb*(1-xt) - P;
end
0 Comments
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!