why is my plot plotting blank?

2 vues (au cours des 30 derniers jours)
Rand Ardat
Rand Ardat le 25 Nov 2020
Commenté : Jon le 25 Nov 2020
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);

Réponses (3)

Jon
Jon le 25 Nov 2020
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 commentaires
Jon
Jon le 25 Nov 2020
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 le 25 Nov 2020
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);

Connectez-vous pour commenter.


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

David Hill
David Hill le 25 Nov 2020
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);

Catégories

En savoir plus sur Plot Customization dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by