Cannot get the plot to work

10 Ansichten (letzte 30 Tage)
Tyler
Tyler am 7 Nov. 2022
Bearbeitet: Askic V am 7 Nov. 2022
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')

Akzeptierte Antwort

Star Strider
Star Strider am 7 Nov. 2022
Bearbeitet: Star Strider am 7 Nov. 2022
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.
.

Weitere Antworten (1)

Askic V
Askic V am 7 Nov. 2022
Bearbeitet: Askic V am 7 Nov. 2022
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?

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by