Struggling to use fzero on this function
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ZM
am 25 Feb. 2018
Beantwortet: Toluwaloju Tunde Isaiah
am 2 Feb. 2021
I am trying to solve for when y=0 with u as the variable for the function below.
When I try v= fzero(@(u) velocity(u,-1,250E-6, 0.13))
MATLAB says:
FZERO requires at least two input arguments or a structure with valid fields.
Any ideas?
function y=velocity(u,z,Ro,H)
p_sat = 2.3393E3; Patm = 100E3; rho_f = 998.21; g = 9.81; Pl = Patm-rho_f*g*z; gamma = 7.28E-2;
p =[Pl-p_sat 2*gamma 0 -(Patm+rho_f*g*H)*Ro^3]; R = roots(p); % get all roots of p R = R(imag®==0); % only keep real roots
Vb=(4.*pi.*R^3)./3;
g = 9.81; rho_f = 998.21; temp = 20+273; R_g = 8.3145; y_air = 1-((p_sat)./(Pl.*((Ro./R).^3))); y_water = 1-y_air; Mr = (28.9647./1000).*y_air + (18./1000)*y_water; Pb = Pl+((2.*gamma)/R); rho_b = (Pb./(R_g.*temp)).*Mr; mu = 0.0010005; d = 2.*R;
Re =((rho_f*u*d)/mu) cd =(24/Re)*(1+0.15*Re.^0.687)
y=Vb.*g.*(rho_f-rho_b)-cd.*((pi.*d.^2)/4)*((rho_f*u.^2)/2)
end
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 25 Feb. 2018
You need to tell fzero either a starting point or an interval in which you know a zero exists. This means fzero needs to be called with at least two inputs (the second of which is a scalar or a 2-element vector) or if you call it with one input that input needs to be a problem structure that contains that information.
1 Kommentar
Jan
am 25 Feb. 2018
Bearbeitet: Jan
am 25 Feb. 2018
+1. Exactly.
@ZM: The error message is clear already
FZERO requires at least two input arguments or a structure
with valid fields.
If you get such a message, start with reading the documentation:
help fzero
You will find the code example X = fzero(FUN,X0) in the first line and this is the solution already: X0 is missing.
Weitere Antworten (2)
Toluwaloju Tunde Isaiah
am 2 Feb. 2021
I am trying to solve the following using the fzero command
L=0.035:-0.001:0
for k=1;
while k<=length(L);
L=L(:,k);
fun_=@(x)det([(cosh(x)+cos(x))-(x.^3)*(In/(M*L.^2))*(sinh(x)+sin(x))-(x.^2)*(Ms/(M*L))*(cosh(x)-cos(x)) (sinh(x)+sin(x))-
(x.^3)*(In/(M*L.^2))*(cosh(x)-cos(x))-(x.^2)*(Ms/(M*L))*(sinh(x)-sin(x)); (sinh(x)-sin(x))+(x)*(m0/M)*(cosh(x)-cos(x))+(x.^2)*
(Ms/(M*L))*(sinh(x)+sin(x)) (cosh(x)+cos(x))+(x)*(m0/M)*(sinh(x)-sin(x))+(x.^2)*(Ms/(M*L))*(cosh(x)-cos(x))]);
fun(k)=fzero(@(x)fun_(x));
fun(k)=fzero(@(x)fun_(x,L));
its = [fzero(fun(k),0.1) fzero(fun(k),0.3) fzero(fun(k),0.5) fzero(fun(k),0.7)];
itss = its(its>0);
betaN = min(itss)
wn=(betaN(k)^2)*sqrt(E*I_s/(Rho*A*(L^4)));
fn=wn/(2*pi)
fprintf('Mode shape # %2f corresponds to nat. freq (wn): %f\n', k, wn(k) );
k=k+1;
end
end
M, L, m0, In, Ms, are known scalers
The Line of error feed back i recieved follows
Error using fzero (line 116)
FZERO requires at least two input arguments or a structure with valid fields.
Error in PiezowithTunability (line 55)
fun(k)=fzero(@(x)fun_(x,L));
0 Kommentare
Siehe auch
Kategorien
Mehr zu Whos 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!