why is my plot plotting blank?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (3개)
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
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
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
2020년 11월 25일
The value of ‘Cd’ is 0 in the code you posted, so ‘y’ is uniformly -Inf.
댓글 수: 0
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Plot Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!