# Please help: In an assignment A(I) = B, the number of elements in B and I must be the same.

1 view (last 30 days)
Guilherme Torres on 20 Apr 2016
Commented: Kuifeng on 21 Apr 2016
I am getting this error: (Please tell me exactly what to change? I am desperate!!) In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in Untitled (line 54)
P(j) = P(j-1)+ delta_p_old/2 * depths;
depths = zeros(1,41);
pressures = zeros(1,41);
% define constant variables
q_o = 500; % bbl/d
T_i = 130; % degrees F
Tubing_ID = 2/12; % feet
Depth = 8000; % feet
API = 28; % dimensionless
mu_l = 1.03; % cp
Y_g = 0.71;
mu_g = 0.0131; % cp
sigma_og = 30; % dynes/cm
pipe_roughness = 0.0006; %dimensionless
P_sc = 14.7; % psia
T_sc = 60 + 460; % degrees F;
delta_z = 0:200:8000; % change in depth iteration of 200 feet to 8000
limit = 42; % iteration limit
iter = 0; % starting iteration
P = zeros(1,41);
%P = zeros(1,41);
P(1) = 100;
depth(1) = 0;
%change_P_new(1) = 200;
%delta_p_new = 200;
error = 2378645;
% P(i) = 100; %psi
for i = 100:100:800 % for loop
q_g = q_o*i;
for j = 2:41
while error > 0.001
if iter ==0
delta_p_old = 200;
end
if iter > 0
delta_p_old = delta_p_new;
%change_P_new = delta_p_new
%change_P_new(j)= delta_p_old/2;
end
P(j) = P(j-1)+ delta_p_old/2 * depths;
%P(j) = P(j-1)+ delta_p_new(0:delta_p_old / 2:8000);
% if iter == 2
% P(i) = P(i) + delta_p_new;
%
%
% end
%for oil
Y_oil = (141.5/(131.5 + API));
rho_l = Y_oil * 62.4;
%for gas and Z factor
P_pc = 709.6 - (58.7 * Y_g);
T_pc = 170.5 + (307.3 * Y_g);
P_pr = P(j)/P_pc;
T_pr = T_i/T_pc;
A = 1.39*(T_pr - 0.92)^0.5 - 0.36*T_pr - 0.101;
B = P_pr*(0.62 - 0.23*T_pr) + P_pr^2 * (0.066/(T_pr-0.86) - 0.037) + (0.32*P_pr^6)/(exp(20.723*(T_pr - 1)));
C = 0.132 - 0.32*log10(T_pr);
D = exp(0.715 - 1.128*T_pr + 0.42*T_pr^2);
Z_fact = A + (1-A) * exp(-B) + C*P_pr^D;
rho_g = (P(j) * Y_g * 28.97)/(Z_fact * 10.73 * T_i);
u_sl = (5.615*q_o)/(86400*0.25*pi*Tubing_ID^2);
u_sg = (1/(86400*0.25*pi*Tubing_ID^2))*q_g*Z_fact*(T_i/T_sc)*(P_sc/P(j));
N_vl = 1.938*u_sl*(rho_l/sigma_og)^0.25;
N_vg = 1.938*u_sg*(rho_l/sigma_og)^0.25;
N_D = 120.872*Tubing_ID*(rho_l/sigma_og)^0.25;
N_L = 0.15726*mu_l*(1/(rho_l*sigma_og^3))^0.25;
CN_L = (0.0019+0.0322*N_L - 0.6642*N_L^2 + 4.9951*N_L^3)/(1-10.0147*N_L + 33.8696*N_L^2 + 277.2817*N_L^3);
H = (N_vl*P(j)^0.1 * CN_L)./((N_vg.^0.575)*P_sc^0.1 * N_D);
yloverpsi = ((0.0047+1123.32*H+729489.64*H.^2)/(1+1097.1566*H+722153.97*H.^2)).^0.5;
B = (N_vg*N_L^0.38)/(N_D^2.14);
psi = (1.0886-69.9473*B.^2 - 12896.683*B.^3)/(1-53.4401*B+1517.9369*B.^2-8419.8115*B.^3);
Liq_Hold_Up = (yloverpsi)*(psi);
rho_bar = Liq_Hold_Up*rho_l+(1-Liq_Hold_Up)*rho_g;
m_dot = (0.25*pi*Tubing_ID^2)*(u_sl*rho_l+u_sg*rho_g)*86400;
N_Re = ((2.2*10^-2)*m_dot)/(Tubing_ID*(mu_l^Liq_Hold_Up)*(mu_g^(1-Liq_Hold_Up)));
one_over_sqrtf = -4.*log((pipe_roughness./3.7065)-(5.0452./N_Re).*log((pipe_roughness.^1.1098./2.8275)+(7.149./N_Re).^0.8981));
dpoverdz = (1/144).*(rho_bar + (m_dot.^2 .* (1./(one_over_sqrtf.^2))./(rho_bar.*7.413*10.^10.*Tubing_ID.^5)));
delta_p_new = dpoverdz*delta_z;
error = abs(delta_p_new - delta_p_old);
iter= iter+1;
depths(j) = j * 200;
%pressures(
end
delta_z = delta_z - 200;
if (delta_z < -8000)
break
end
end
plot(P, depths)
end

Kuifeng on 20 Apr 2016
depths = zeros(1,41); %it has 41 elements and P(j) is one element.
% maybe you wanted to use
depths(j)?
Kuifeng on 21 Apr 2016
how about crop a picture of these variables in the workspace?