Cannot get the plot to work

13 ビュー (過去 30 日間)
Tyler
Tyler 2022 年 11 月 7 日
編集済み: Askic V 2022 年 11 月 7 日
clear,clc
alt0=0;
altStep=2;
numAlt=5000;
alt=alt0:altStep:(alt0+altStep*(numAlt-1));
p=.7444;
K=.0234;
cD0=.0069;
W=1918.733*9.81;
lapse=(-6.5*10^-3);
S=12.6;
CL32OVCDmax=.25*((3/(K*(cD0^(1/3))))^.75);
Psealevel=11*10^3;
seaLevelrho = 1.225;
seaLevelTemp = 294;
RCmax=zeros;
for i=1:numAlt
altTemp = seaLevelTemp + alt(i)*lapse;
altrho = seaLevelrho*(altTemp/seaLevelTemp)^(((-9.81/lapse)/287)-1);
Palt=Psealevel*((altrho/seaLevelrho)^.7);
vMaxROC=((2/p)*(sqrt((K/(3*cD0)))*W/S))^.5;
maxROC=Palt/W-(sqrt(2*W))/(sqrt(altrho*S)*CL32OVCDmax);
end
plot(alt,maxROC,'.r')
xlabel('Altitude (m)')
ylabel('Maximum achiveable R/C')

採用された回答

Star Strider
Star Strider 2022 年 11 月 7 日
編集済み: Star Strider 2022 年 11 月 7 日
Subscript ‘maxROC’
maxROC(i)=Palt/W-(sqrt(2*W))/(sqrt(altrho*S)*CL32OVCDmax);
The plot then appears.
The problem is that ‘maxROC’ is overwritten in the loop otherwise, so only the last value appears. MATLAB does not plot single points unless a marker is specified.
alt0=0;
altStep=2;
numAlt=5000;
alt=alt0:altStep:(alt0+altStep*(numAlt-1));
p=.7444;
K=.0234;
cD0=.0069;
W=1918.733*9.81;
lapse=(-6.5*10^-3);
S=12.6;
CL32OVCDmax=.25*((3/(K*(cD0^(1/3))))^.75);
Psealevel=11*10^3;
seaLevelrho = 1.225;
seaLevelTemp = 294;
RCmax=zeros;
for i=1:numAlt
altTemp = seaLevelTemp + alt(i)*lapse;
altrho = seaLevelrho*(altTemp/seaLevelTemp)^(((-9.81/lapse)/287)-1);
Palt=Psealevel*((altrho/seaLevelrho)^.7);
vMaxROC=((2/p)*(sqrt((K/(3*cD0)))*W/S))^.5;
maxROC(i)=Palt/W-(sqrt(2*W))/(sqrt(altrho*S)*CL32OVCDmax);
end
figure
plot(alt,maxROC,'.r')
xlabel('Altitude (m)')
ylabel('Maximum achiveable R/C')
EDIT — Corrected typographical errors.
.

その他の回答 (1 件)

Askic V
Askic V 2022 年 11 月 7 日
編集済み: Askic V 2022 年 11 月 7 日
Please use " toggle code" option when posting Malab code. It looks better.
The reason you're not getting what you expect is that variable maxROC is a single double number i.e. constant and alt is an array of dimensions (1, 5000).
Perhaps this is what you want:
clear,clc
alt0=0;
altStep=2;
numAlt=5000;
alt=alt0:altStep:(alt0+altStep*(numAlt-1));
p=.7444;
K=.0234;
cD0=.0069;
W=1918.733*9.81;
lapse=(-6.5*10^-3);
S=12.6;
CL32OVCDmax=.25*((3/(K*(cD0^(1/3))))^.75);
Psealevel=11*10^3;
seaLevelrho = 1.225;
seaLevelTemp = 294;
RCmax=zeros;
for i=1:numAlt
altTemp = seaLevelTemp + alt(i)*lapse;
altrho = seaLevelrho*(altTemp/seaLevelTemp)^(((-9.81/lapse)/287)-1);
Palt=Psealevel*((altrho/seaLevelrho)^.7);
vMaxROC=((2/p)*(sqrt((K/(3*cD0)))*W/S))^.5;
% make maxROC an array
maxROC(i)=Palt/W-(sqrt(2*W))/(sqrt(altrho*S)*CL32OVCDmax);
end
plot(alt,maxROC,'.r')
xlabel('Altitude (m)')
ylabel('Maximum achiveable R/C')
BTW, what is the point of vMaxROC and having it inside the loop especially?

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by