why is my plot plotting blank?

19 次查看(过去 30 天)
Rand Ardat
Rand Ardat 2020-11-25
评论: Jon 2020-11-25
g = 9.8 %m/s^2
rohp = 1800 %kg/m3
Dp = 0.208*10^(-3); %m
T = 298.15 %K
roh = 994.6 %kg/m3
vis = 8.931*10.^-4 %kg/m · s
Vt=0:0.1:60
Re=roh*Vt*Dp/vis
Cd=zeros(1)
if Re>0.1 & Re<=1000
Cd= (24./Re).*(1+0.14*(Re.^0.7));
end
thvis=@(Vt) Vt-((4.*g.*(rohp-roh).*Dp)./(3.*Cd.*roh)).^(0.5)
dthvis=@(Vt) 1
y=thvis(Vt);
plot(Vt,y);

回答(3 个)

Jon
Jon 2020-11-25
The reason your plot is blank is because all of your y values are infinite. They are infinite because Cd is zero for all of your points and Cd is in the denominator of your calculation. Note that you initialize your Cd to zero, and then because you never satisfy the if statement on Reynolds number range it remains zero.
  2 个评论
Jon
Jon 2020-11-25
More fundamentally your if statement will not assign multiple elements of Cd. Instead you could do something like
idx = Re>0.1&Re<1000;
Cd(idx) = (24./Re(idx)).*(1+0.14*(Re(idx).^0.7))
Jon
Jon 2020-11-25
Actually you probably just want to work with values that are in the correct Re range you could do it like this
g = 9.8 %m/s^2
rohp = 1800 %kg/m3
Dp = 0.208*10^(-3); %m
T = 298.15 %K
roh = 994.6 %kg/m3
vis = 8.931*10.^-4 %kg/m · s
Vt=0:0.1:60
Re=roh*Vt*Dp/vis
% just keep values that are in Reynolds range
idx = Re>0.1&Re<1000;
Cd = (24./Re(idx)).*(1+0.14*(Re(idx).^0.7))
Vt = Vt(idx);
% calculate and plot function values
thvis=@(Vt) Vt-((4.*g.*(rohp-roh).*Dp)./(3.*Cd.*roh)).^(0.5)
y=thvis(Vt);
plot(Vt,y);

请先登录,再进行评论。


Star Strider
Star Strider 2020-11-25
The value of ‘Cd’ is 0 in the code you posted, so ‘y’ is uniformly -Inf.

David Hill
David Hill 2020-11-25
g = 9.8; %m/s^2
rohp = 1800;%kg/m3
Dp = 0.208e-3; %m
T = 298.15; %K
roh = 994.6; %kg/m3
vis = 8.931e-4; %kg/m · s
Vt=0:0.1:60;
Re=roh*Vt*Dp/vis;
Cd=zeros(size(Re));
Cd(Re>.1&Re<=1000)=(24./Re(Re>.1&Re<=1000)).*(1+0.14*(Re(Re>.1&Re<=1000).^0.7));
thvis=@(Vt) Vt-((4*g*(rohp-roh)*Dp)./(3*Cd*roh)).^(0.5);
y=thvis(Vt);
plot(Vt,y);

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by