Why isnt plot working for this code?

조회 수: 1 (최근 30일)
Rithwik Jayanth
Rithwik Jayanth 2021년 10월 25일
답변: Star Strider 2021년 10월 25일
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');
  댓글 수: 1
VBBV
VBBV 2021년 10월 25일
You dont need a for loop for your code

댓글을 달려면 로그인하십시오.

답변 (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
  댓글 수: 2
Rithwik Jayanth
Rithwik Jayanth 2021년 10월 25일
Thank you so much!
Rithwik Jayanth
Rithwik Jayanth 2021년 10월 25일
one question
Why didnt it work with the for loop?

댓글을 달려면 로그인하십시오.


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