フィルターのクリア

Error using sym/subs Inconsistency between sizes of second and third arguments.

10 ビュー (過去 30 日間)
Robert
Robert 2023 年 10 月 22 日
コメント済み: Walter Roberson 2023 年 10 月 22 日
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)
solutionRe1 = Empty sym: 0-by-1
calculateRe1 = double(subs(solutionRe1,[p,V,D1,mu_u],[p_val,V_val,D1_val,mu_u_val]));
disp(['Re1 = ' num2str(calculateRe1)]);
Re1 =
%calculate B
solutionB1 = solve(equationB,B1)
solutionB1 = Empty sym: 0-by-1
calculateB1 = double(subs(solutionB1,Re1,calculateRe1));
disp(['B1 = ' num2str(calculateB1)]);
B1 =
%calculate A
solutionA1 = solve(equationA,A1)
solutionA1 = Empty sym: 0-by-1
size([Re1,epsilon,D1])
ans = 1×2
1 3
size([calculateRe1,epsilon_val,D1_val])
ans = 1×2
1 2
calculateA1 = double(subs(solutionA1,[Re1,epsilon,D1],[calculateRe1,epsilon_val,D1_val]));
Error using sym/subs
Inconsistency between sizes of second and third arguments.
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 件)

Torsten
Torsten 2023 年 10 月 22 日
編集済み: Torsten 2023 年 10 月 22 日
You cannot subs a vector of size 1x2 for a vector of size 1x3 (see above).

Walter Roberson
Walter Roberson 2023 年 10 月 22 日
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)
solutionRe1 = Empty sym: 0-by-1
calculateRe1 = double(subs(solutionRe1,{p,V,D1,mu_u},{p_val,V_val,D1_val,mu_u_val}));
disp(['Re1 = ' num2str(calculateRe1)]);
Re1 =
%calculate B
solutionB1 = solve(equationB,B1)
solutionB1 = Empty sym: 0-by-1
calculateB1 = double(subs(solutionB1,Re1,calculateRe1));
disp(['B1 = ' num2str(calculateB1)]);
B1 =
%calculate A
solutionA1 = solve(equationA,A1)
solutionA1 = Empty sym: 0-by-1
calculateA1 = double(subs(solutionA1,{Re1,epsilon,D1},{calculateRe1,epsilon_val,D1_val}));
disp(['A1 = ' num2str(calculateA1)])
A1 =
%solving for the Darcy friction factor
solutionf1 = solve(darcy_friction_factor_eqn,f1)
solutionf1 = Empty sym: 0-by-1
calculatef1 = double(subs(solutionf1,{Re1,A1,B1},{calculateRe1,calculateA1,calculateB1}));
disp(['f1 = ' num2str(calculatef1)]);
f1 =
%solving for the major head loss
solutionH_L1 = solve(head_loss_eqn1,h_L1)
solutionH_L1 = Empty sym: 0-by-1
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']);
The major head loss is h_L1 = m
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 10 月 22 日
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
Walter Roberson 2023 年 10 月 22 日
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));

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by