why is my plot plotting blank?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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);
0 comentarios
Respuestas (3)
Jon
el 25 de Nov. de 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 comentarios
Jon
el 25 de Nov. de 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
el 25 de Nov. de 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);
Star Strider
el 25 de Nov. de 2020
The value of ‘Cd’ is 0 in the code you posted, so ‘y’ is uniformly -Inf.
0 comentarios
David Hill
el 25 de Nov. de 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);
0 comentarios
Ver también
Categorías
Más información sobre Plot Customization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!