vpasolve unable to find solution of 6 simultaneous equations
1 view (last 30 days)
Show older comments
Hi there,
I am trying to use vpasolve to solve 6 simultaneous equations in which i need 7 variables solved for.
My matlab code is as follows:
Alt = 6562 * 0.3048; %Altitude (m)
M = 6300; %Aircraft mass (kg)
pos_cg = 0.29; %Centre of Gravity position
FPA = 0 * (pi/180); %Fligth Path Angle (Radians)
g0 = 9.81; %Gravitational Constant (m/s^2)
%Valid up to 36000 ft
R = 287.5; %Gas constant (Nm/kgK)
Lr = -0.0065; %Lapse Rate (K/m)
T = 288.16 +(Lr * Alt); %Temperature (K)
Rho = 1.225 * ((T/288.16)^-((g0/(Lr * R))+1)); %Air Density (kg/m^3)
Sigma = Rho/1.225; %Density ratio
%Note that true airspeed is assumed unless otherwise stated
V_knots_vector = zeros(10,1);
for i=1:1:10
V_knots = 100+(15 * i);%True airspeed range
V_knots_vector(i) = V_knots;
end
V_i = V_knots_vector * 0.515; %True airspeed
V_eas_i = V_knots_vector * sqrt(Sigma); %Equivalent airspeed
S = 25.08; %Wing area (m^2)
b = 15.85; %Wing span (m)
c_w = 1.716; %Wing mean chord (m)
Sweep = 0; %Sweep at 1/4Cw (deg)
Z_w = 0.45; %Z coordinate of 1/4Cw point above (-ve) or below (+ve) ox body axis (m)
alpha_wr = 1.0 * (pi/180); %Wing riggle angle (rads)
S_T = 7.79; %Tailplane area (m^2)
b_T = 6.6; %Tailplane span (m)
l_t = 6.184; %Tail arm, 1/4Cw to 1/4Ct (m)
Z_t = -1.435; %Z coordinate of 1/4Cw point above (-ve) or below (+ve) ox body axis (m)
n_T = 1.5 * (pi/180); %Tail setting angle (rad)
F_d = 1.981; %Fuselage diameter or width (m)
Z_tau = 0.312; %Thrust line z coordinate above (-ve) or below (+ve) ox body axis (m)
k = 0 * (pi/180); %Engine thrust line angle relative to ox body axis (+nose up) (rad)
%Insert values defined by the installed wing aerodynamic design
a = 5.19; %Wing body CL-alpha (per rad)
CL_max = 1.37; %Maximum lift coefficient
C_m0 = -0.0711; %Zero lift pitching moment
CD_0 = 0.03; %Zero lift drag coefficient
alpha_w0 = -2 * (pi/180); %Zero lift angle of attack (rad)
h_0 = -0.08; %Wing-body aero centre
%Insert values defined by the tailplane aerodynamic centre
a1 = 3.2; %Tailplane CL-alpha (per rad)
a2 = 2.414; %Elevator CL-n (per rad)
epsilon_0 = 2.0 * (pi/180); %Zero lift downwash angle (rad)
AR = b^2/S; %Aspect Ratio
s = b/2; %Wing semi-span (m)
l_T = l_t - (c_w * (pos_cg - 0.25)); %Tail arm, cg to 1/4ct (m)
V_T = (S_T * l_T)/(S * c_w); %Tail volume
x = l_t/b; %Tail position relative to wing (% of Span)
z = (Z_w - Z_t)/b; %Tail position relative to wing (% of Span)
fivector = zeros(81,1);
for fi=5:1:85
indivfi = ((0.5 * cos((fi * pi)/180)^2)/(sqrt(x^2 + (0.5 * cos((fi * pi)/180))^2 + z^2))) * ((((x + sqrt(x^2 + (0.5 * cos((fi * pi)/180))^2 + z^2))/((0.5 * cos((fi * pi)/180))^2 + z^2)) + ((x)/(x^2 + z^2))) * pi/180);
fivector(fi) = indivfi;
end
sumfi = sum(fivector);
d_epsilonalpha = (a/(((pi)^2) * AR))*sumfi;
%Drag Polar defined as CD = Cd_0 + KCL^2
s_d = 0.9998 + (0.0421*(F_d/b)) - (2.6286*(F_d/b)^2) + (2.000*(F_d/b)^3); %Fuselage drag factor
K_D = (-3.333e-04 * Sweep^2) + (6.667e-05 * Sweep) + 0.38; %Emperical constant
e = 1/(pi * AR * K_D * CD_0 +(1/(0.99 * s_d))); %Oswald efficiency factor
K = 1/(pi * AR * e); %Induced drag factor
V_md = ((sqrt((2 * M * g0)/(Rho * S)))*(K/CD_0)^0.25) * (1/0.515); %Minimum drag speed (knots)
V_mdeas = V_md * sqrt(Sigma); % Equivalent minimum drag speed (knots)
V_stall = sqrt((2 * M * g0)/(Rho * S * CL_max))*(1/0.515); %Stall speed (knots)
V_stalleas = V_stall * sqrt(Sigma); %Equivalent stall speed (knots)
h_n = h_0 + (V_T * (a1/a) * (1 - d_epsilonalpha)); %Neutral point - controls fixed
K_n = h_n - pos_cg; %Static margin - controls fixed
%Trim computation finds the trim condition for each speed defined in the
%speed range table
syms V_i alpha_e C_tau C_D C_LT C_LW CL
Y = vpasolve((2*(M*g0)/Rho*(V_i^2)*S)*sin(alpha_e + FPA) == C_tau*cos(k) - C_D*cos(alpha_e) + CL*sin(alpha_e), (2*(M*g0)/Rho*(V_i^2)*S)*cos(alpha_e + FPA) == CL*cos(alpha_e) - C_D*sin(alpha_e) + C_tau*sin(k), 0 == (C_m0 + (pos_cg - h_0)*C_LW) - (V_T*C_LT) + (C_tau * (Z_tau/c_w)), CL == C_LW + (C_LT * (S_T)/S), C_D == CD_0 + K*(CL)^2, C_LW == a*(alpha_e + alpha_wr - alpha_w0), [CL,C_D,C_LT,C_LW,C_tau,V_i,alpha_e])
However i recieve an output of:
CL: [0x1 sym]
C_D: [0x1 sym]
C_LT: [0x1 sym]
C_LW: [0x1 sym]
C_tau: [0x1 sym]
V_i: [0x1 sym]
alpha_1: [0x1 sym]
It might be helpful to note that V_i is a 10 x 1 vector and i need to find the values of CL, C_D ect for each of the values of V.
Also apologies for the code length but i beleive that most of the terms are needed for the solving.
Any help/ alterations to my code would be highly appreciated. :)
1 Comment
Accepted Answer
Torsten
on 4 Feb 2023
Edited: Torsten
on 4 Feb 2023
A corrected version of the last part of your code would be
Alt = 6562 * 0.3048; %Altitude (m)
M = 6300; %Aircraft mass (kg)
pos_cg = 0.29; %Centre of Gravity position
FPA = 0 * (pi/180); %Fligth Path Angle (Radians)
g0 = 9.81; %Gravitational Constant (m/s^2)
%Valid up to 36000 ft
R = 287.5; %Gas constant (Nm/kgK)
Lr = -0.0065; %Lapse Rate (K/m)
T = 288.16 +(Lr * Alt); %Temperature (K)
Rho = 1.225 * ((T/288.16)^-((g0/(Lr * R))+1)); %Air Density (kg/m^3)
Sigma = Rho/1.225; %Density ratio
%Note that true airspeed is assumed unless otherwise stated
V_knots_vector = zeros(10,1);
for i=1:1:10
V_knots = 100+(15 * i);%True airspeed range
V_knots_vector(i) = V_knots;
end
V_i = V_knots_vector * 0.515; %True airspeed
V_eas_i = V_knots_vector * sqrt(Sigma); %Equivalent airspeed
S = 25.08; %Wing area (m^2)
b = 15.85; %Wing span (m)
c_w = 1.716; %Wing mean chord (m)
Sweep = 0; %Sweep at 1/4Cw (deg)
Z_w = 0.45; %Z coordinate of 1/4Cw point above (-ve) or below (+ve) ox body axis (m)
alpha_wr = 1.0 * (pi/180); %Wing riggle angle (rads)
S_T = 7.79; %Tailplane area (m^2)
b_T = 6.6; %Tailplane span (m)
l_t = 6.184; %Tail arm, 1/4Cw to 1/4Ct (m)
Z_t = -1.435; %Z coordinate of 1/4Cw point above (-ve) or below (+ve) ox body axis (m)
n_T = 1.5 * (pi/180); %Tail setting angle (rad)
F_d = 1.981; %Fuselage diameter or width (m)
Z_tau = 0.312; %Thrust line z coordinate above (-ve) or below (+ve) ox body axis (m)
k = 0 * (pi/180); %Engine thrust line angle relative to ox body axis (+nose up) (rad)
%Insert values defined by the installed wing aerodynamic design
a = 5.19; %Wing body CL-alpha (per rad)
CL_max = 1.37; %Maximum lift coefficient
C_m0 = -0.0711; %Zero lift pitching moment
CD_0 = 0.03; %Zero lift drag coefficient
alpha_w0 = -2 * (pi/180); %Zero lift angle of attack (rad)
h_0 = -0.08; %Wing-body aero centre
%Insert values defined by the tailplane aerodynamic centre
a1 = 3.2; %Tailplane CL-alpha (per rad)
a2 = 2.414; %Elevator CL-n (per rad)
epsilon_0 = 2.0 * (pi/180); %Zero lift downwash angle (rad)
AR = b^2/S; %Aspect Ratio
s = b/2; %Wing semi-span (m)
l_T = l_t - (c_w * (pos_cg - 0.25)); %Tail arm, cg to 1/4ct (m)
V_T = (S_T * l_T)/(S * c_w); %Tail volume
x = l_t/b; %Tail position relative to wing (% of Span)
z = (Z_w - Z_t)/b; %Tail position relative to wing (% of Span)
fivector = zeros(81,1);
for fi=5:1:85
indivfi = ((0.5 * cos((fi * pi)/180)^2)/(sqrt(x^2 + (0.5 * cos((fi * pi)/180))^2 + z^2))) * ((((x + sqrt(x^2 + (0.5 * cos((fi * pi)/180))^2 + z^2))/((0.5 * cos((fi * pi)/180))^2 + z^2)) + ((x)/(x^2 + z^2))) * pi/180);
fivector(fi) = indivfi;
end
sumfi = sum(fivector);
d_epsilonalpha = (a/(((pi)^2) * AR))*sumfi;
%Drag Polar defined as CD = Cd_0 + KCL^2
s_d = 0.9998 + (0.0421*(F_d/b)) - (2.6286*(F_d/b)^2) + (2.000*(F_d/b)^3); %Fuselage drag factor
K_D = (-3.333e-04 * Sweep^2) + (6.667e-05 * Sweep) + 0.38; %Emperical constant
e = 1/(pi * AR * K_D * CD_0 +(1/(0.99 * s_d))); %Oswald efficiency factor
K = 1/(pi * AR * e); %Induced drag factor
V_md = ((sqrt((2 * M * g0)/(Rho * S)))*(K/CD_0)^0.25) * (1/0.515); %Minimum drag speed (knots)
V_mdeas = V_md * sqrt(Sigma); % Equivalent minimum drag speed (knots)
V_stall = sqrt((2 * M * g0)/(Rho * S * CL_max))*(1/0.515); %Stall speed (knots)
V_stalleas = V_stall * sqrt(Sigma); %Equivalent stall speed (knots)
h_n = h_0 + (V_T * (a1/a) * (1 - d_epsilonalpha)); %Neutral point - controls fixed
K_n = h_n - pos_cg; %Static margin - controls fixed
%Trim computation finds the trim condition for each speed defined in the
%speed range table
syms V_is alpha_e C_tau C_D C_LT C_LW CL
eqns = [2*M*g0/(Rho*V_is^2*S)*sin(alpha_e + FPA) == C_tau*cos(k) - C_D*cos(alpha_e) + CL*sin(alpha_e),...
2*M*g0/(Rho*V_is^2*S)*cos(alpha_e + FPA) == CL*cos(alpha_e) + C_D*sin(alpha_e) + C_tau*sin(k),...
0 == (C_m0 + (pos_cg - h_0)*C_LW) - (V_T*C_LT) + (C_tau * (Z_tau/c_w)),...
CL == C_LW + (C_LT * S_T/S),...
C_D == CD_0 + K*(CL)^2,...
C_LW == a*(alpha_e + alpha_wr - alpha_w0)]
for i = 1:10
sol{i} = vpasolve(subs(eqns,V_is,V_i(i)),[CL,C_D,C_LT,C_LW,C_tau,alpha_e],[0.7,0.02,0.1,0.5,0.4,0.1]);
end
sol{1}
sol{2}
sol{3}
sol{4}
sol{5}
sol{6}
sol{7}
sol{8}
sol{9}
sol{10}
However, vpasolve is not able to find a solution.
4 Comments
More Answers (1)
Walter Roberson
on 4 Feb 2023
You need to arrayfun or loop over elements of V_i as vpasolve and solve try to solve all of the passed equations simultaneously
See Also
Categories
Find more on General Applications 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!