Error using sym/subs Inconsistency between sizes of second and third arguments.
10 views (last 30 days)
Show older comments
syms f1 f2 Re1 Re2 A1 A2 B1 B2 epsilon D1 D2 p V mu_u v h_L1 h_L2 k_L1 k_L2 g L1 L2 delta_P
head_loss_eqn1 = [h_L1,h_L2] == [(V.^2/(2*g))*(f1*(L1/D1)+k_L1), (V.^2/(2*g))*(f1*(L1/D1)+k_L1)];
darcy_friction_factor_eqn = [f1,f2] == [8*((8/Re1).^12 + (A1+B1).^-1.5).^(1/12),8*((8/Re2).^12 + (A2+B2).^-1.5).^(1/12)];
equationA = [A1,A2] == [(-2.457*log((7/Re1).^0.9 + 0.27*(epsilon/D1))).^16 , (-2.457*log((7/Re2).^0.9 + 0.27*(epsilon/D2))).^16];
equationB = [B1,B2] == [(37530/Re1).^16,(37530/Re2).^16];
Renolds_eqn1 =[Re1,Re2] == [(p*V*D1)/mu_u,(p*V*D2)/mu_u];
%values
D1_val = 0.012;
L1_val = 2.82; %length of the section of pipe under consideration
epsilon_val = 1.04e-5;
V_val = 6.00;
Re_val= [];
mu_u_val = 1.00e-3; %viscosity of water at 20 degrees celcius
p_val = 1000;
k_L1_val = 0;
g_val = 9.807;
%calculate Re using the Re1 equation
solutionRe1 = solve(Renolds_eqn1,Re1)
calculateRe1 = double(subs(solutionRe1,[p,V,D1,mu_u],[p_val,V_val,D1_val,mu_u_val]));
disp(['Re1 = ' num2str(calculateRe1)]);
%calculate B
solutionB1 = solve(equationB,B1)
calculateB1 = double(subs(solutionB1,Re1,calculateRe1));
disp(['B1 = ' num2str(calculateB1)]);
%calculate A
solutionA1 = solve(equationA,A1)
size([Re1,epsilon,D1])
size([calculateRe1,epsilon_val,D1_val])
calculateA1 = double(subs(solutionA1,[Re1,epsilon,D1],[calculateRe1,epsilon_val,D1_val]));
disp(['A1 = ' num2str(calculateA1)]);
%solving for the Darcy friction factor
solutionf1 = solve(darcy_friction_factor_eqn,f1);
calculatef1 = double(subs(solutionf1,[Re1,A1,B1],[calculateRe1,calculateA1,calculateB1]));
disp(['f1 = ' num2str(calculatef1)]);
%solving for the major head loss
solutionH_L1 = solve(head_loss_eqn1,h_L1);
calculateH_L1 = double(subs(solutionH_L1,[f1,L1,D1,V,g,k_L1],[calculatef1,L1_val,D1_val,V_val,g_val,k_L1_val]));
disp(['The major head loss is h_L1 = ' num2str(calculateH_L1) 'm']);
0 Comments
Answers (2)
Walter Roberson
on 22 Oct 2023
syms f1 f2 Re1 Re2 A1 A2 B1 B2 epsilon D1 D2 p V mu_u v h_L1 h_L2 k_L1 k_L2 g L1 L2 delta_P
head_loss_eqn1 = [h_L1,h_L2] == [(V.^2/(2*g))*(f1*(L1/D1)+k_L1), (V.^2/(2*g))*(f1*(L1/D1)+k_L1)];
darcy_friction_factor_eqn = [f1,f2] == [8*((8/Re1).^12 + (A1+B1).^-1.5).^(1/12),8*((8/Re2).^12 + (A2+B2).^-1.5).^(1/12)];
equationA = [A1,A2] == [(-2.457*log((7/Re1).^0.9 + 0.27*(epsilon/D1))).^16 , (-2.457*log((7/Re2).^0.9 + 0.27*(epsilon/D2))).^16];
equationB = [B1,B2] == [(37530/Re1).^16,(37530/Re2).^16];
Renolds_eqn1 =[Re1,Re2] == [(p*V*D1)/mu_u,(p*V*D2)/mu_u];
%values
D1_val = 0.012;
L1_val = 2.82; %length of the section of pipe under consideration
epsilon_val = 1.04e-5;
V_val = 6.00;
Re_val= [];
mu_u_val = 1.00e-3; %viscosity of water at 20 degrees celcius
p_val = 1000;
k_L1_val = 0;
g_val = 9.807;
%calculate Re using the Re1 equation
solutionRe1 = solve(Renolds_eqn1,Re1)
calculateRe1 = double(subs(solutionRe1,{p,V,D1,mu_u},{p_val,V_val,D1_val,mu_u_val}));
disp(['Re1 = ' num2str(calculateRe1)]);
%calculate B
solutionB1 = solve(equationB,B1)
calculateB1 = double(subs(solutionB1,Re1,calculateRe1));
disp(['B1 = ' num2str(calculateB1)]);
%calculate A
solutionA1 = solve(equationA,A1)
calculateA1 = double(subs(solutionA1,{Re1,epsilon,D1},{calculateRe1,epsilon_val,D1_val}));
disp(['A1 = ' num2str(calculateA1)])
%solving for the Darcy friction factor
solutionf1 = solve(darcy_friction_factor_eqn,f1)
calculatef1 = double(subs(solutionf1,{Re1,A1,B1},{calculateRe1,calculateA1,calculateB1}));
disp(['f1 = ' num2str(calculatef1)]);
%solving for the major head loss
solutionH_L1 = solve(head_loss_eqn1,h_L1)
calculateH_L1 = double(subs(solutionH_L1,{f1,L1,D1,V,g,k_L1},{calculatef1,L1_val,D1_val,V_val,g_val,k_L1_val}));
disp(['The major head loss is h_L1 = ' num2str(calculateH_L1) 'm']);
2 Comments
Walter Roberson
on 22 Oct 2023
So why are you not getting any solutions at all, at any point?
Renolds_eqn1 =[Re1,Re2] == [(p*V*D1)/mu_u,(p*V*D2)/mu_u];
That is a pair of equations
solutionRe1 = solve(Renolds_eqn1,Re1)
That you are asking to solve for a single variable. You must, in nearly all cases, ask to solve for the same number of variables as you have equations.
Walter Roberson
on 22 Oct 2023
Note that your right hand sides do not involve Re1 or Re2, so there is no point in invoking solve() -- just assign
solutionRe1 = rhs(Renolds_eqn1(1));
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!