Pretty simple on fzero
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2015-2-19
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.
回答(1 个)
Torsten
2015-2-18
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!