How do I make an efficient While loop? setting true = 0, then while true = 0, results in an error on the while line. of code. What is wrong with that logic?

1 次查看(过去 30 天)
I want to run this while loop, and want to make sure i am doing it an efficient manner. I'm a beginner level matlab user in college. I want the loop to run until I meet the condition that WoCalculated be within 99.99% of WoGuess.
Wfinal_Wo = FinalLand.*ReturnCruise_Wi.*TotalClimbingWeightFraction.*TotalLandingWeightFraction.*w3_w2.*w2_w1.*w1_wo;
Wfuel_Wo = 1.06.*(1-Wfinal_Wo);
WoGuess = 95000;
WoCalculated = 1;
% Wempty_Wo = 1.09*Wo.^-.05
true = 0;
while true = 0
We_Wo = 1.09.*WoGuess.^-.05;
%Weight of water and crew is 25,500 and 750 respectively
WoCalculated = (26250)./(1 - Wfuel_Wo - We_Wo);
if (WoCalculated/WoGuess) >= .9999
true = 1;
else
WoGuess = WoCalculated;
end
end

回答(1 个)

jonas
jonas 2018-9-30
编辑:jonas 2018-9-30

Use == for logical operations. Also do not call your variable true. Writing

while true=0

is very counterintuitive, as true has a specific meaning in matlab.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by