Having problems with logarithmic value

1 次查看(过去 30 天)
% Time t=1 to end. Notice that t=1 is in t(2).
Given, t = 2500*1
Qin = 7; % Inflow [ml/s]
r = 2.5; % Radius bucket [cm]
A = pi*r^2; % Bucket area [cm^2]
H = 30; % Bucket height [cm]
rh = 0.1; % Bottom hole radius [cm]
Ah = pi*rh^2; % Area hole [cm^2]
g = 981; % Acceleration due to gravity [cm/s^2]
rho = 1; % Density of water [g/cm^3]
mu = 0.01; % Viscosity of water [g/(cm s)]
dt = 0.01; % Time step [s]
total_time = 250; % Total simulation time [s]
step = 0:250/dt; % Iteration steps [step]
t = step*dt; % Time of simulation [s]
% Look up Reynolds number and coefficient of discharge.
Re_table = [1 10 100 1000 10000 100000]; % Reynolds number
Re_table = log10(Re_table); % Take log10 to allow linear interpolation.
CD_table = [0.04 0.28 0.73 0.74 0.64 0.61 ];% Coefficient of discharge
for row = 2:length(t)
for col = 1:3
Re(row,col) = (2*rh*rho)/mu*sqrt(g*h(row,col)-2);
CD(row,col) = interp1(Re_table,CD_table,log10(Re(row,col)));
Qout(row,col) = CD(row,col)*Ah*sqrt(2*g*h(row,col)); % [cm^3/s]
h_out = Qout(row-1,col)/A;
h_in = Qin/A;
h_increment = dt*(h_in - h_out);
h(row,col) = min(h(row,col)-2+ h_increment, H);
end
end
while getting h values, i got nan value. I do not know how to get rid of that values. It has to start with 0, then small increment and after some time, will got maximum value(30cm) but I am getting 0, then 28.03 and same values until end and for second ht and third height, initial height is Nan.
Thank you advance for help.

回答(1 个)

Star Strider
Star Strider 2015-10-2
I can’t run your code because I don’t have an initial value for ‘h’. However, one possible source of your NaN value is attempting to extrapolate with interp1 without telling it you want to extrapolate.
See if this prevents the NaN value from appearing:
CD(row,col) = interp1(Re_table,CD_table,log10(Re(row,col)), 'linear', 'extrap');

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by