How do I fix my P_ups function?
古いコメントを表示
clear
clc
global P_atm
global P_tube
global tube_ID
global tube_L
global ball_D
global x
global v
global a_dens
global TR
global P_rupt
ball_D = 0.04; %meters
ball_m = 0.00275; %kg
tube_OD = 0.05; %meters
tube_ID = 0.04; %meters
tube_L = 1.52; %meters
P_atm = 101.4; %kPa
dt = 0.00001; %time intervals
K = 0.78; %entrance coefficient
f = 0.018; %friction coefficient
a_dens = 1.225; %kg/m^3
A_ball = pi*(ball_D/2)^2;
P_rupt = 250; %kPa
j = 1;
for P_tube = 1:1:10
TR = 0;
i = 1;
time(i) = 0;
v(i) = 0;
x(i) = 0.02;
P_ds(i) = P_tube;
P_ups(i) = 0;
while x(i) <= tube_L-ball_D/2
P_ups(i) = P_upsCalc(i);
P_ds(i) = P_dsCalc(i);
F_ups(i) = A_ball * P_ups(i) * 1000;
F_ds(i) = A_ball * P_ds(i) * 1000;
a(i) = (F_ups(i) - F_ds(i)) / ball_m;
time(i+1) = time(i) + dt;
v(i+1) = v(i) + a(i)*dt;
x(i+1) = x(i) + v(i+1)*dt;
i = i + 1;
end
Velocity(j) = v(i);
Pressure(j) = P_tube;
j = j + 1;
end
plot(Pressure, Velocity)
xlabel("Pressure (kPa)")
ylabel("Velocity (m/sec)")
function P_ds = P_dsCalc(b)
global tube_ID
global tube_L
global ball_D
global x
global P_tube
global P_atm
global P_rupt
global TR
Volume_init = pi*(tube_ID/2)^2*(tube_L - ball_D/2);
Volume_inter = pi.*(tube_ID/2)^2*(tube_L -ball_D/2 - x(b));
Volume_inter = max(Volume_inter, 1e-6);
if TR == 1
P_ds = P_atm;
return
end
P_ds = P_tube * (Volume_init / Volume_inter)^1.4;
P_ds = min(P_ds, 300);
if P_ds >= P_rupt
TR = 1;
P_ds = P_atm;
end
end
function P_ups = P_upsCalc(d)
global P_atm a_dens K f tube_L tube_ID v
v_local = v(d); % guaranteed scalar
P_b = 0.5 * a_dens * (v_local^2);
P_f = (f * tube_L * a_dens * (v_local^2)) / (2 * tube_ID);
P_k = K * (0.5 * a_dens * (v_local^2));
P_ups = P_atm - P_b - P_f - P_k;
P_ups = max(P_ups, 0);
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Assembly についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
