Code loop logic issue
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
Im trying to make a takeoff weight estimation code formy course and im having some issues trying to figure out the logic for then code. the code is meant to calculate a value of weight using a set of predetermined values and compare it to the guessed value which is input. I have it set up so that if the calculated value does not match the guessed one its meant to loop the code using a new value. However i can only get it to don one loop before stopping, Any help would be appreciated.
Thank you
close;
clear;
Wguess=input('input weight guess');
WTO=input('input original weight');
WE=input('input empty weight');
WF=input('input fuel weight');
WPAY=input('input payload weight');
AW0=WE/WTO;
WFRAC=WF/WTO;
Wcalc=(WPAY)/(1-WFRAC-AW0);
if Wcalc==Wguess
WTO=Wcalc;
else
Wguess=Wcalc;
Wcalc=(WPAY)/(1-(WF/WTO)-(WE/WTO));
end
0 件のコメント
回答 (1 件)
Tushar Behera
2023 年 2 月 5 日
編集済み: Tushar Behera
2023 年 2 月 5 日
Hi Takura
I believe you want to loop through the code until the guessed value is equal to the calculated value.
In order to acheive that you can use a while loop to iterate over your code. For example,
close;
clear;
Wguess=input('input weight guess');
WTO=input('input original weight');
WE=input('input empty weight');
WF=input('input fuel weight');
WPAY=input('input payload weight');
AW0=WE/WTO;
WFRAC=WF/WTO;
% Start a while loop to repeat the process until the guessed value is correct
while Wcalc ~= Wguess
Wcalc=(WPAY)/(1-WFRAC-AW0);
% Check if the calculated value matches the guessed value
if Wcalc==Wguess
WTO=Wcalc;
break;
end
% Update the guessed value for the next iteration
Wguess=Wcalc;
Wcalc=(WPAY)/(1-(WF/WTO)-(WE/WTO));
end
% Display the final takeoff weight
disp(['The takeoff weight is: ' num2str(WTO)])
I hope this resolves your query.
Regards,
Tushar
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!