multiple simultaneuous equations solver gives error

%Initial seed values for solve block
C_L = 0.7;
C_L_w = 0.5;
C_D = 0.02;
C_tau = 0.4;
alpha_e = 0.1;
C_LT = 0.1;
i = [0 1 2 3 4 5 6 7 8 9 10];
V_knots = 100 + 15*i; %True airspeed range (knots)
V_i = V_knots*0.515; %true airspeed (m/s)
syms C_L C_D C_tau alpha_e C_LT C_LW
% eqn1 = C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) - 2*m*g/(rho*V_i^2*S)*sin(alpha_e+gamma_e) == 0;
% eqn2 = C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) - 2*m*g/(rho*V_i^2*S)*cos(alpha_e+gamma_e) == 0;
% eqn3 = C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0;
% eqn4 = C_L - C_LT*S_T/S - C_L_w == 0;
% eqn5 = K*C_L^2 - C_D + C_D0 == 0;
% eqn6 = a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0;
for i = V_i
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i(i)^2*S)*sin(alpha_e+gamma_e),
C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) == 2*m*g/(rho*V_i(i)^2*S)*cos(alpha_e+gamma_e),
C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0,
C_L - C_LT*S_T/S - C_L_w == 0,
K*C_L^2 - C_D + C_D0 == 0,
a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0];
S(i) = vpasolve(eqns, [C_L(i), C_D(i), C_tau(i), alpha_e(i), C_LT(i), C_LW(i)])
end
gives the error:
Array indices must be positive integers or logical values.
Error in aeroTrim (line 153)
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i(i)^2*S)*sin(alpha_e+gamma_e),
Please advise on how i can fix this and find the values for the variables. Thank you

1 件のコメント

Torsten
Torsten 2022 年 2 月 17 日
編集済み: Torsten 2022 年 2 月 17 日
You use
for i = V_i
and V_i is complex-valued.
So you can't index arrays with i.

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

 採用された回答

Star Strider
Star Strider 2022 年 2 月 17 日

0 投票

Array indices must be positive integers or logical values.
The ‘V_1’ are not integers.
Try something like this instead —
V_iv = V_knots*0.515; %true airspeed (m/s)
then —
for i = 1:numel(V_iv)
V_i = V_iv(i);
...
end
Note that in the posted code, several variables are neither defined nor declared. Declating them —
%Initial seed values for solve block
C_L = 0.7;
C_L_w = 0.5;
C_D = 0.02;
C_tau = 0.4;
alpha_e = 0.1;
C_LT = 0.1;
i = [0 1 2 3 4 5 6 7 8 9 10];
V_knots = 100 + 15*i; %True airspeed range (knots)
V_iv = V_knots*0.515; %true airspeed (m/s)
syms C_L C_D C_tau alpha_e C_LT C_LW
syms kappa m g rho S gamma_e z_tau c_w V_T C_m0 h h_0 S_T K C_D0 a alpha_wr alpha_w0
% eqn1 = C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) - 2*m*g/(rho*V_i^2*S)*sin(alpha_e+gamma_e) == 0;
% eqn2 = C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) - 2*m*g/(rho*V_i^2*S)*cos(alpha_e+gamma_e) == 0;
% eqn3 = C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0;
% eqn4 = C_L - C_LT*S_T/S - C_L_w == 0;
% eqn5 = K*C_L^2 - C_D + C_D0 == 0;
% eqn6 = a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0;
for i = 1:numel(V_iv)
V_i = V_iv(i);
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i(i)^2*S)*sin(alpha_e+gamma_e),
C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) == 2*m*g/(rho*V_i(i)^2*S)*cos(alpha_e+gamma_e),
C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0,
C_L - C_LT*S_T/S - C_L_w == 0,
K*C_L^2 - C_D + C_D0 == 0,
a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0];
% S(i) = vpasolve(eqns, [C_L(i), C_D(i), C_tau(i), alpha_e(i), C_LT(i), C_LW(i)])
S = solve(eqns, [C_L(i), C_D(i), C_tau(i), alpha_e(i), C_LT(i), C_LW(i)])
end
S = struct with fields:
C_L: [0×1 sym] C_D: [0×1 sym] C_tau: [0×1 sym] alpha_e: [0×1 sym] C_LT: [0×1 sym] C_LW: [0×1 sym]
Index exceeds the number of array elements. Index must not exceed 1.
So the loop problem is solved snd the code executes. It is not possible to go further without numeric values for the undefined constants.
.

5 件のコメント

Punit Ahuja
Punit Ahuja 2022 年 2 月 17 日
I've taken your suggestion and included the new code below.
To make it easier, i've equated all of the constants to 1.
%Initial seed values for solve block
C_L = 0.7;
C_L_w = 0.5;
C_D = 0.02;
C_tau = 0.4;
alpha_e = 0.1;
C_LT = 0.1;
i = [0 1 2 3 4 5 6 7 8 9 10];
V_knots = 100 + 15*i; %True airspeed range (knots)
V_iv = V_knots*0.515; %true airspeed (m/s)
kappa = 1; m=1; g=1; rho=1; S=1; gamma_e=1; z_tau=1; c_w=1; V_T=1; C_m0=1; h=1;
h_0=1; S_T=1; K=1; C_D0=1; a=1; alpha_wr=1; alpha_w0=1;
syms C_L C_D C_tau alpha_e C_LT C_LW
for i = 1:numel(V_iv)
V_i = V_iv(i);
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i(i)^2*S)*sin(alpha_e+gamma_e),
C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) == 2*m*g/(rho*V_i(i)^2*S)*cos(alpha_e+gamma_e),
C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0,
C_L - C_LT*S_T/S - C_L_w == 0,
K*C_L^2 - C_D + C_D0 == 0,
a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0];
S = solve(eqns, [C_L(i), C_D(i), C_tau(i), alpha_e(i), C_LT(i), C_LW(i)])
end
Is it now possible to solve these?
Sorry for not including them the first time.
I also get this in the command window after running the code:
S =
struct with fields:
C_L: [0×1 sym]
C_D: [0×1 sym]
C_tau: [0×1 sym]
alpha_e: [0×1 sym]
C_LT: [0×1 sym]
C_LW: [0×1 sym]
Index exceeds the number of array elements. Index must not exceed 1.
Error in aeroTrim (line 153)
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i(i)^2*S)*sin(alpha_e+gamma_e),
Star Strider
Star Strider 2022 年 2 月 17 日
Please do not subscript ‘V_i’ because in each loop iteration it is a scalar —
%Initial seed values for solve block
C_L = 0.7;
C_L_w = 0.5;
C_D = 0.02;
C_tau = 0.4;
alpha_e = 0.1;
C_LT = 0.1;
i = [0 1 2 3 4 5 6 7 8 9 10];
V_knots = 100 + 15*i; %True airspeed range (knots)
V_iv = V_knots*0.515; %true airspeed (m/s)
kappa = 1; m=1; g=1; rho=1; S=1; gamma_e=1; z_tau=1; c_w=1; V_T=1; C_m0=1; h=1;
h_0=1; S_T=1; K=1; C_D0=1; a=1; alpha_wr=1; alpha_w0=1;
syms C_L C_D C_tau alpha_e C_LT C_LW
for i = 1:numel(V_iv)
V_i = V_iv(i);
eqns = [C_L*sin(alpha_e) - C_D*cos(alpha_e) + C_tau*cos(kappa) == 2*m*g/(rho*V_i^2*S)*sin(alpha_e+gamma_e),
C_L*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(kappa) == 2*m*g/(rho*V_i^2*S)*cos(alpha_e+gamma_e),
C_tau*z_tau/c_w - V_T*C_LT + (C_m0 + (h-h_0)*C_L_w) == 0,
C_L - C_LT*S_T/S - C_L_w == 0,
K*C_L^2 - C_D + C_D0 == 0,
a*(alpha_e + alpha_wr - alpha_w0) - C_L_w == 0];
% S = solve(eqns, [C_L(i), C_D(i), C_tau(i), alpha_e(i), C_LT(i), C_LW(i)])
[C_Ls{i}, C_Ds{i}, C_taus{i}, alpha_es{i}, C_LTs{i}, C_LWs{i}] = solve(eqns, [C_L, C_D, C_tau, alpha_e, C_LT, C_LW]);
end
C_Ls
C_Ls = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
C_Ds
C_Ds = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
C_taus
C_taus = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
alpha_es
alpha_es = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
C_LTs
C_LTs = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
C_LWs
C_LWs = 1×11 cell array
{0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym} {0×1 sym}
I made some slight changes and it runs without error.
The problem is that it does not produce any useful results, at least in its present form. Different values for the other variables (all now set equal to 1) may change that.
.
Punit Ahuja
Punit Ahuja 2022 年 2 月 17 日
thank you good sir
Star Strider
Star Strider 2022 年 2 月 17 日
As always, my pleasure!
Alex Sha
Alex Sha 2022 年 2 月 18 日
Numerical Solutions:
i C_L C_D C_TAU ALPHA_E C_LT C_L_W
0 0.821020148353258 1.67407408400201 -1.86495420551723 1.68597435387049 -0.864954205517232 1.68597435387049
1 0.821023762637745 1.67408001881584 -1.86486589916737 1.68588966180511 -0.864865899167367 1.68588966180511
2 0.821026195663131 1.67408401396507 -1.86480635574535 1.68583255140848 -0.864806355745349 1.68583255140848
3 0.821027911515128 1.67408683148689 -1.86476431593763 1.68579222745276 -0.864764315937635 1.68579222745276
4 0.821029166792955 1.67408889272473 -1.86473353548028 1.68576270227323 -0.864733535480275 1.68576270227323
5 0.821030112773441 1.67409044608077 -1.86471032520523 1.68574043797867 -0.864710325205233 1.68574043797867
6 0.821030843345073 1.67409164572392 -1.8646923918575 1.68572323520257 -0.864692391857501 1.68572323520257
7 0.821031419287761 1.67409259145767 -1.86467824909721 1.68570966838497 -0.864678249097213 1.68570966838497
8 0.82103188135886 1.67409335020767 -1.86466689930221 1.68569878066107 -0.86466689930221 1.68569878066107
9 0.821032257718414 1.6740939682142 -1.86465765269067 1.68568991040908 -0.864657652690667 1.68568991040908
10 0.821032568329102 1.67409447825708 -1.86465001998691 1.68568258831601 -0.864650019986908 1.68568258831601

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

その他の回答 (0 件)

カテゴリ

質問済み:

2022 年 2 月 17 日

コメント済み:

2022 年 2 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by