Matlab cannot recognize variable
이전 댓글 표시
I have this code here.
%May change entire thing to function
clc;
clear;
%Variables
sigma = .1;
lock = 8;
twist = -8;
a = 5.7*(180/pi);
bloading = .12;
mu = .25;
alpha_tpp = 2.25;
siga = sigma*a; % This variable is seen a lot.
%% solve for inflow
% Change
CT = .0012;
lambdaH = sqrt(CT/2);
muz = mu*tand(alpha_tpp);
aproxerr = 10^5;
esterr = 100;
n = 0;
f = .5;
while aproxerr < esterr
n = n+1;
if n == 1
lambdaold = lambdaH;
else
lambdaold = lambda;
end
%iterating on
lambdain = lambdaH^2/(sqrt(lambdaold^2+mu^2));
lambda = lambdaold - (lambdaold - muz - lambdain)/(1+((lambdain*lambdaold)/(lambdaold^2+mu^2)))*f;
esterr = abs(lambda - lambdaold)/lambda;
end
%% Question 2
delta = 1 - mu^2 + (9/4*mu^4);
%theta_collective =
%(1/delta)*((1+((3/2)*mu^2)))*((6*CT)/(sigma*a)+(.375*mu^2*twist) I
%do not know if this is necessary
Betanaught = ((lock/8)/delta)*(1-((19/18)*mu^2)+(1.5*mu^4))*((6*CT)/siga)+(.005+((29/120)*mu^2)-(.2*mu^4)+(.375*mu^6))*twist + lambda*((1/6)-((7/12)*mu^2)+(.25*mu^4));
Why is Lambda unrecognized here? I ran another code that had pretty much the same iteration up until the end of the while loop, and lambda was defined in it. So what is wrong here? And btw, I appreciate all the help you guys offer me.
Other code for reference
format long
% lambda is x
Rmain=27; %ft
Cmain=1.7; %ft
Nbmain=4;
Tipspeed_main=725; %ft/s
W=16000; %lb
alt=5000;
alpha_tpp=3;
%knots
%%
Amain=pi*Rmain^2;
sigma=(Nbmain*Cmain)/(pi*Rmain);
[~, ~, ~, RHO] = atmosisa(alt*0.3048);
rho=RHO*0.0685218/35.3147;
CT = W/(rho*Amain*Tipspeed_main^2);
xh = sqrt(CT/2);
V = 0*1.68781:10*1.68781:200*1.68791;
Mu = V./(Tipspeed_main);
for k1=1:length(Mu)
mu=Mu(k1);
muz = mu*tand(alpha_tpp);
n = 0;
aperr = 10^-5;
eserr = 100;
while eserr > aperr
n = n + 1;
if n == 1
xold = xh;
else
xold = x ;
end
%iterating on
xin = xh.^2./sqrt(xold.^2+mu.^2);
x = xold - (xold - muz - xin)./(1+((xin.*xold)./(xold.^2+mu.^2))).*.5;
eserr = abs((x - xold)./x);
end
X(k1)=x;
end
figure
plot(Mu,X,'-x')
grid on
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!