Cannot get the plot to work

2 views (last 30 days)
Tyler
Tyler on 7 Nov 2022
Edited: Askic V on 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')

Accepted Answer

Star Strider
Star Strider on 7 Nov 2022
Edited: Star Strider on 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.
.

More Answers (1)

Askic V
Askic V on 7 Nov 2022
Edited: Askic V on 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?

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!