Cannot get the plot to work

조회 수: 12 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by