Pretty simple on fzero
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 19 Fév 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.
Réponses (1)
Torsten
le 18 Fév 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Function Creation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!