Pretty simple on fzero
16 ビュー (過去 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!