Why isnt plot working for this code?

2 次查看(过去 30 天)
Hi, Im a still new to MatLab. I am not sure why the plot function is not plotting anything for my code
p = 0.002378*(1-0.0000068756*2000)^4.2561;
v=100;
AR = 7;
q = 0.5*p*v^2;
n = 1/cos(45);
e = 1.78*(1-0.045*AR^0.68)-0.64;
k = 1/(3.14*AR*e);
Vv = 25;
Vlof = 65;
u = 0.04;
g = 9.81;
Cdmin = 0.025;
Sg = 1000;
Clto = 0.5;
Cdto = 0.04;
figure
for WS = 0:70
TW1 = Vv/v + q/WS*Cdmin + k/q*WS;
TW2 = Vlof^2/(2*g*Sg) + q*Cdto/WS + u*(1-q*Clto/WS);
TW3 = q*(Cdmin/WS + k*(n/q)^2*WS);
% TW4 = q*(Cdmin/WS + k*(n/q)^2*WS) + Ps/V;
TW5 = q*Cdmin/WS + k/q*WS;
TW6 = Vv/sqrt(2/p*WS * sqrt(3/(3*Cdmin))) + 4*sqrt(k*Cdmin/3);
%plot(TW1,WS,'g',TW2,WS,'b',TW3,WS,'r',TW4,WS,'m',TW5,WS,'k',TW6,WS);
hold on
plot(WS,TW1,'g',WS,TW2,'b',WS,TW3,'r',WS,TW5,'k',WS,TW6,'y');
end
hold off
xlabel('W/S');
ylabel('T/W');

回答(2 个)

VBBV
VBBV 2021-10-25
p = 0.002378*(1-0.0000068756*2000)^4.2561;
v=100;
AR = 7;
q = 0.5*p*v^2;
n = 1/cos(45);
e = 1.78*(1-0.045*AR^0.68)-0.64;
k = 1/(3.14*AR*e);
Vv = 25;
Vlof = 65;
u = 0.04;
g = 9.81;
Cdmin = 0.025;
Sg = 1000;
Clto = 0.5;
Cdto = 0.04;
figure
WS = 0:70;
TW1 = Vv/v + q./WS*Cdmin + k./q*WS;
TW2 = Vlof^2/(2*g*Sg) + q*Cdto./WS + u*(1-q*Clto./WS);
TW3 = q*(Cdmin./WS + k*(n/q)^2.*WS);
TW5 = q*Cdmin./WS + k./q*WS;
TW6 = Vv./sqrt(2./p*WS * sqrt(3/(3*Cdmin))) + 4*sqrt(k*Cdmin/3);
plot(WS,TW1,'g',WS,TW2,'b',WS,TW3,'r',WS,TW5,'k',WS,TW6,'y');
%hold off
xlabel('W/S');
ylabel('T/W');
legend

Star Strider
Star Strider 2021-10-25
It will work with the for loop if (1) the plot call plots points instead of lines, or (2) if the values are subscripted inside the loop and plotted afterwards. This is because plot plots lines between points, not points themsleves, so either define markers or create vectors for the variables.
Plotting points —
p = 0.002378*(1-0.0000068756*2000)^4.2561;
v=100;
AR = 7;
q = 0.5*p*v^2;
n = 1/cos(45);
e = 1.78*(1-0.045*AR^0.68)-0.64;
k = 1/(3.14*AR*e);
Vv = 25;
Vlof = 65;
u = 0.04;
g = 9.81;
Cdmin = 0.025;
Sg = 1000;
Clto = 0.5;
Cdto = 0.04;
figure
for WS = 0:70
TW1 = Vv/v + q/WS*Cdmin + k/q*WS;
TW2 = Vlof^2/(2*g*Sg) + q*Cdto/WS + u*(1-q*Clto/WS);
TW3 = q*(Cdmin/WS + k*(n/q)^2*WS);
% TW4 = q*(Cdmin/WS + k*(n/q)^2*WS) + Ps/V;
TW5 = q*Cdmin/WS + k/q*WS;
TW6 = Vv/sqrt(2/p*WS * sqrt(3/(3*Cdmin))) + 4*sqrt(k*Cdmin/3);
%plot(TW1,WS,'g',TW2,WS,'b',TW3,WS,'r',TW4,WS,'m',TW5,WS,'k',TW6,WS);
hold on
plot(WS,TW1,'.g',WS,TW2,'.b',WS,TW3,'.r',WS,TW5,'.k',WS,TW6,'.y');
end
hold off
xlabel('W/S');
ylabel('T/W');
Plotting vectors —
p = 0.002378*(1-0.0000068756*2000)^4.2561;
v=100;
AR = 7;
q = 0.5*p*v^2;
n = 1/cos(45);
e = 1.78*(1-0.045*AR^0.68)-0.64;
k = 1/(3.14*AR*e);
Vv = 25;
Vlof = 65;
u = 0.04;
g = 9.81;
Cdmin = 0.025;
Sg = 1000;
Clto = 0.5;
Cdto = 0.04;
WSv = 0:70;
for k1 = 1:numel(WSv)
WS = WSv(k1);
TW1(k1) = Vv/v + q/WS*Cdmin + k/q*WS;
TW2(k1) = Vlof^2/(2*g*Sg) + q*Cdto/WS + u*(1-q*Clto/WS);
TW3(k1) = q*(Cdmin/WS + k*(n/q)^2*WS);
% TW4 = q*(Cdmin/WS + k*(n/q)^2*WS) + Ps/V;
TW5(k1) = q*Cdmin/WS + k/q*WS;
TW6(k1) = Vv/sqrt(2/p*WS * sqrt(3/(3*Cdmin))) + 4*sqrt(k*Cdmin/3);
%plot(TW1,WS,'g',TW2,WS,'b',TW3,WS,'r',TW4,WS,'m',TW5,WS,'k',TW6,WS);
end
figure
plot(WSv,TW1,'g',WSv,TW2,'b',WSv,TW3,'r',WSv,TW5,'k',WSv,TW6,'y');
xlabel('W/S');
ylabel('T/W');
Experiment to get different results.
.

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by