Cannot get the plot to work
1 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
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.
.
0 个评论
更多回答(1 个)
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?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!