Pretty simple on fzero

10 visualizaciones (últimos 30 días)
Adam Stofko
Adam Stofko el 18 de Feb. de 2015
Comentada: Geoff Hayes el 19 de Feb. de 2015
I keep getting an error with the code bellow. I've gonna about this a couple of different way but still nothing. What I'm i going wrong?
function Trim
%Givens
delta=60000; %lbs
LCG=29; %ft
b=14; %ft
B=18; %degrees
V=67.5; %ft/s
a=1.39; %dt
f=0.5; %ft
e=4; % degrees
v=1.052e-5;
global x
%---------EQ's-------------
%C--------
Cv=3.18;
lamda= 64.267./ x^2.2;
C= LCG-(0.75-1./(5.21*(Cv./lamda)^2+2.39)*lamda*b);
%Df-------
V1= V*(1-0.0675./(lamda*cosd(x)))^(1/2);
Lk= lamda*b+(b*tand(B))./(2*pi*tand(x));
Re= V1*Lk./v;
Cf=0.075./(log10(Re)-2)^2;
Df= Cf*1.99*V1^2*lamda*b^2./(2*cosd(B));
%solve for Trim-------
X=fzero(@(x) delta.*((1-sind(lamda).*sind(x+e))./cosd(x).*C-f.*sind(x))+Df.*(a-f), 4)
end
  3 comentarios
Adam Stofko
Adam Stofko el 18 de Feb. de 2015
Operands to the and && operators must be convertible to logical scalar values.
Error in fzero (line 308) elseif ~isfinite(fx) ~isreal(fx)
Error in Trim (line 37) X=fzero(@(x) delta.*((1-sind(lamda).*sind(x+e))./cosd(x).*C-f.*sind(x))+Df.*(a-f), 4)
Geoff Hayes
Geoff Hayes el 19 de Feb. de 2015
Adam - in the line
global x
what is x defined to be? If it hasn't been defined, then it is an empty matrix and so lambda is initialized to an empty matrix too. This seems to cause the error that you are observing. Please verify that x is initialized correctly and review whether it should be a global variable or just a local variable or an input to this function.

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 18 de Feb. de 2015
function call
X0=4;
X=fzero(@f,X0);
function y=f(x)
delta=60000; %lbs
LCG=29; %ft
b=14; %ft
B=18; %degrees
V=67.5; %ft/s
a=1.39; %dt
f=0.5; %ft
e=4; % degrees
v=1.052e-5;
%---------EQ's-------------
%C--------
Cv=3.18;
lamda= 64.267./ x^2.2;
C= LCG-(0.75-1./(5.21*(Cv./lamda)^2+2.39)*lamda*b);
%Df-------
V1= V*(1-0.0675./(lamda*cosd(x)))^(1/2);
Lk= lamda*b+(b*tand(B))./(2*pi*tand(x));
Re= V1*Lk./v;
Cf=0.075./(log10(Re)-2)^2;
Df= Cf*1.99*V1^2*lamda*b^2./(2*cosd(B));
y=delta.*((1-sind(lamda).*sind(x+e))./cosd(x).*C-f.*sind(x))+Df.*(a-f);
end
Best wishes
Torsten.

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by