Pretty simple on fzero
조회 수: 13 (최근 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!