Code will not plot graph when I try to change my payload vector increment.

10 ビュー (過去 30 日間)
Hannah Pike
Hannah Pike 2020 年 11 月 29 日
コメント済み: Yogi 2023 年 11 月 28 日
My code is supposed to display a plot of the Range vs Payload of an aircraft, however, when I try and change the increment of my payload vector from 100, the plot comes up blank. It will not even include my title or axes labels. Let me know what I need to fix to allow me to change my increment and still have the plot display. It shows there is a potential error with the length of the payload and the range vectors when it gets to the point of plotting if I change the incerment.
% PAYLOAD CALULATIONS
TotalPassengerWeight = Passengers * PassengerWeight;
TotalLuggageWeight = Luggage * LuggageWeight;
MaxPayload = TotalPassengerWeight + TotalLuggageWeight;
Payload = [0:100:MaxPayload];
% FUEL CALCULATIONS
i = 1;
while Payload <= MaxPayload & i <= length(MaxPayload)
Fuel(i) = MaxTakeOff - EmptyWeight - Payload(i) - TotalCrewWeight; %kg
i = i + 1;
end
TakeOffFuel = .995 .* Fuel;
ClimbFuel = .980 .* Fuel;
DescentFuel = .990 .* Fuel;
LoiterFuel = .987 .* Fuel;
LandFuel = .992 .* Fuel;
TakeOffFuelUsed = Fuel - TakeOffFuel;
ClimbFuelUsed = Fuel - ClimbFuel;
DescentFuelUsed = Fuel - DescentFuel;
LoiterFuelUsed = Fuel - LoiterFuel;
LandFuelUsed = Fuel - LandFuel;
FuelUsed = TakeOffFuelUsed + ClimbFuelUsed + DescentFuelUsed + LoiterFuelUsed + LandFuelUsed;
% WEIGHT CALCULATIONS
InitialWeight = MaxTakeOff;
FinalWeight = MaxTakeOff - (Fuel - FuelUsed);
% RANGE CALCULATION
Range = (PropellerEfficiency / Ct) * (LtoD) * log(InitialWeight ./ FinalWeight); %m
% PLOT.
figure(1)
hold on
plot(Payload,Range,"r-");
title("Range(m) vs Payload(kg) of a Propeller Aircraft");
xlabel("Payload(m)");
ylabel("Range(m)");
grid on
hold off

採用された回答

Image Analyst
Image Analyst 2020 年 11 月 29 日
You're not using the correction I gave you in your other post:
while (i <= length(Payload)) && (Payload(i) <= MaxPayload)
Why not?
Plus, realize that Fuel is a vector so all the other things will also vectors.
If you need more help, give us the missing code to assign the variables that are needed to run your program.
  3 件のコメント
Image Analyst
Image Analyst 2020 年 11 月 29 日
This works and makes a plot:
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
MaxTakeOff = 4750; %(kg) Max Takeoff Weight
EmptyWeight = 2810; %(kg) Empty Weight
MaxFuelCapacity = 1225; %(kg) Max Fuel Capacity
Crew = 1; %people Number of Crew Members
Passengers = 8; %people Number of Passengers
LtoD = 15; % Lift to Drage Ratio
PropellerEfficiency = .8; % Propeller Efficiency
Ct = 1.92; %Specific Fuel Consumption
CrewWeight = 65; %kg Average Weight of a Crew Member
PassengerWeight = 75; %kg Average Weight of a Passenger
Luggage = 8; %items Number of items a passenger is allowed to have
LuggageWeight = 25; %kg
TotalCrewWeight = Crew * CrewWeight; %kg
% PAYLOAD CALULATIONS
TotalPassengerWeight = Passengers * PassengerWeight;
TotalLuggageWeight = Luggage * LuggageWeight;
MaxPayload = TotalPassengerWeight + TotalLuggageWeight;
Payload = [0:100:MaxPayload];
% FUEL CALCULATIONS
i = 1;
while (i <= length(Payload)) && (Payload(i) <= MaxPayload)
Fuel(i) = MaxTakeOff - EmptyWeight - Payload(i) - TotalCrewWeight; %kg
i = i + 1;
end
TakeOffFuel = .995 .* Fuel;
ClimbFuel = .980 .* Fuel;
DescentFuel = .990 .* Fuel;
LoiterFuel = .987 .* Fuel;
LandFuel = .992 .* Fuel;
TakeOffFuelUsed = Fuel - TakeOffFuel;
ClimbFuelUsed = Fuel - ClimbFuel;
DescentFuelUsed = Fuel - DescentFuel;
LoiterFuelUsed = Fuel - LoiterFuel;
LandFuelUsed = Fuel - LandFuel;
FuelUsed = TakeOffFuelUsed + ClimbFuelUsed + DescentFuelUsed + LoiterFuelUsed + LandFuelUsed;
% WEIGHT CALCULATIONS
InitialWeight = MaxTakeOff;
FinalWeight = MaxTakeOff - (Fuel - FuelUsed);
% RANGE CALCULATION
Range = (PropellerEfficiency / Ct) * (LtoD) * log(InitialWeight ./ FinalWeight); %m
% PLOT Randy (Y) vs. Payload (X).
plot(Payload, Range, 'r.-', 'LineWidth', 2, 'markerSize', 30);
title("Range(m) vs Payload(kg) of a Propeller Aircraft", 'FontSize', fontSize);
xlabel("Payload(m)", 'FontSize', fontSize);
ylabel("Range(m)", 'FontSize', fontSize);
grid on
hold off
Hannah Pike
Hannah Pike 2020 年 11 月 29 日
Great, Thank You!

サインインしてコメントする。

その他の回答 (1 件)

Yogi
Yogi 2023 年 11 月 28 日
Halo Hanna, Can i ask for the full code of Payload-Range diagram? Thank you for your sincerity
  3 件のコメント
Yogi
Yogi 2023 年 11 月 28 日
I've tried it, but some parameters haven't been defined
Yogi
Yogi 2023 年 11 月 28 日
Ohh sorry I didn't read the comment section I just copied on code on the post

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by