Clear Filters
Clear Filters

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 view (last 30 days)
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

Answers (1)

jonas
jonas on 30 Sep 2018
Edited: jonas on 30 Sep 2018

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.

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!