multiple simultaneuous equations solver gives error

16 views (last 30 days)
%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 Comment
Torsten
Torsten on 17 Feb 2022
Edited: Torsten on 17 Feb 2022
You use
for i = V_i
and V_i is complex-valued.
So you can't index arrays with i.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 17 Feb 2022
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 Comments
Alex Sha
Alex Sha on 18 Feb 2022
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!