Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-79201.
2 次查看(过去 30 天)
显示 更早的评论
Hi. First of all sorry for asking the same question again and again but I am really close to the solution (maybe not). I have 2 questions.
1) This code tries to solve 6 ODEs with 6 state variables [horizontal position (x1 and x2), altitude (x3), the true airspeed (x4), the heading angle (x5) and the mass of the aircraft (x6)] and 3 control inputs [engine thrust (u1), the bank angle (u2) and the flight path angle (u3)] by using Euler's method. Different flight maneuvers are performed for the specified time intervals.
Velocities.m, Cruise_Vel.m, Des_Vel.m, Thr_cl.m, Thr_cr.m, Thr_des.m, fuel_cl.m, fuel_cr.m, fuel_des.m,den.m,den_cr.m,den_des.m,drag.m,drag_cr.m,drag_des.m,lift.m,lift_cr.m,lift_des.m are functions in seperate tabs. Code in the main file (Flight.m) is:
% Climb from h1=1100 [m] to h2=1600 [m] with α=5 flight path angle.
% Perform cruise flight for t=60 minutes.
% Turn with β=30 bank angle until heading is changed by η=270◦.
% Descent from h2=1600 [m] to h1=1100 [m] with ζ=4◦ flight path angle.
% Complete a 360◦ turn (loiter) at level flight.
% Descent to h3=800 [m] with κ=4.5◦ flight path angle.
% Aircraft Properties
W = .44225E+06; % .44225E+03 tons = .44225E+06 kg
S = .51097E+03; % Surface Area [m^2]
g0 = 9.80665; % Gravitational acceleration [m/s2]
x6 = W;
% solving 1st order ODE using numerical methods
t0=0;
tend=3960;
h=0.05;
N=(tend-t0)/h;
t=t0:h:tend;
x = zeros(6,length(t));
% Initial conditions
x(:,1)=[0;0;3608.92;1.0e+02 * 1.161544478045788;0;W];
for i=2:length(t)
if and (x(3,i-1) > 3608.92,x(3,i-1)<=5249.3) % Climb from h1=1100 [m] to h2=1600 [m] with α=5 flight path angle.
t =0:60;
x4 = Velocities(3608.9:5249.3); % Changing speed [m/s]
x5 = 0; % Changing head angle [deg]
f = fuel_cl(3608.9:5249.3); % Changing fuel flow [kg/min]
u1 = Thr_cl(3608.9:5249.3); % Changing thrust [N]
u2 = 0; % Changing bank angle [deg]
u3 = 5; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag(3608.9:5249.3,x4); % Changing drag coefficient
Cl = lift(3608.9:5249.3,x4); % Changing lift coefficient
p = den(3608.9:5249.3); % Changing density [kg/m3]
elseif and (x(3,i-1) > 5249.3,x(3,i-1)<=5249.3) % Perform cruise flight for t=60 minutes.
for t=60:3660
x4 = Cruise_Vel(5249.3); % Changing speed [m/s]
x5 = 0; % Changing head angle [deg]
f = fuel_cr(5249.3); % Changing fuel flow [kg/min]
u1 = Thr_cr(5249.3); % Changing thrust [N]
u2 = 0; % Changing bank angle [deg]
u3 = 0; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag_cr(5249.3,x4); % Changing drag coefficient
Cl = lift_cr(5249.3,x4); % Changing lift coefficient
p = den_cr(5249.3); % Changing density [kg/m3]
end
% Turn with β=30 bank angle until heading is changed by η=270◦.
for t=3660:3720
x4 = Cruise_Vel(5249.3); % Changing speed [m/s]
x5 = 0:30:270; % Changing head angle [deg]
f = fuel_cr(5249.3); % Changing fuel flow [kg/min]
u1 = Thr_cr(5249.3); % Changing thrust [N]
u2 = 30; % Changing bank angle [deg]
u3 = 0; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag_cr(5249.3,x4); % Changing drag coefficient
Cl = lift_cr(5249.3,x4); % Changing lift coefficient
p = den_cr(5249.3); % Changing density [kg/m3]
end
elseif and (x(3,i-1) < 5249.3,x(3,i-1)>=3608.9) % Descent from h2=1600 [m] to h1=1100 [m] with ζ=4◦ flight path angle.
t=3720:3780;
x4 = Des_Vel(5249.3,3608.9); % Changing speed [m/s]
x5 = 270; % Changing head angle [deg]
f = fuel_des(5249.3,3608.9); % Changing fuel flow [kg/min]
u1 = Thr_des(5249.3,3608.9); % Changing thrust [N]
u2 = 0; % Changing bank angle [deg]
u3 = 4; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag_des(5249.3,3608.9,x4); % Changing drag coefficient
Cl = lift_des(5249.3,3608.9,x4); % Changing lift coefficient
p = den_des(5249.3,3608.9); % Changing density [kg/m3]
elseif and (x(3,i-1) < 3608.9,x(3,i-1)>=3608.9) % Complete a 360◦ turn (loiter) at level flight.
t = 3780:3900;
x4 = Cruise_Vel(3608.9); % Changing speed [m/s]
lon = [270 300 360 60 120 180 240 270];
x5 = wrapTo360(lon); % Changing head angle [deg]
f = fuel_cr(3608.9); % Changing fuel flow [kg/min]
u1 = Thr_cr(3608.9); % Changing thrust [N]
u2 = 0; % Changing bank angle [deg]
u3 = 0; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag_cr(3608.9,x4); % Changing drag coefficient
Cl = lift_cr(3608.9,x4); % Changing lift coefficient
p = den_cr(3608.9); % Changing density [kg/m3]
elseif and (x(3,i-1) < 3608.9,x(3,i-1)>=2624.67) % Descent to h3=800 [m] with κ=4.5◦ flight path angle.
t=3900:3960;
x4 = Des_Vel(3608.9,2624.67); % Changing speed [m/s]
x5 = 270; % Changing head angle [deg]
f = fuel_des(3608.9,2624.67); % Changing fuel flow [kg/min]
u1 = Thr_des(3608.9,2624.67); % Changing thrust [N]
u2 = 0; % Changing bank angle [deg]
u3 = 4.5; % Changing flight path angle [deg]
V_ver = x4*sin(u3); % Changing vertical speed [m/s]
C_D = drag_des(3608.9,2624.67,x4); % Changing drag coefficient
Cl = lift_des(3608.9,2624.67,x4); % Changing lift coefficient
p = den_des(3608.9,2624.67); % Changing density [kg/m3]
else
fprintf("A problem occured.");
end
dx1dt = x4 .* cos(x5) .* cos(u3);
dx2dt = x4 .* sin(x5) .* cos(u3);
dx3dt = x4 .* sin(u3);
dx4dt = -C_D.*S.*p.*(x4.^2)./(2.*x6)-g0.*sin(u3)+u1./x6;
dx5dt = -Cl.*S.*p.*x4./(2.*x6).*sin(u2);
dx6dt = -f;
x(1,i)= x(1,i-1) + h * dx1dt; %%% line 136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x(2,i)= x(2,i-1) + h * dx2dt;
x(3,i)= x(3,i-1) + h * dx3dt;
x(4,i)= x(4,i-1) + h * dx4dt;
x(5,i)= x(5,i-1) + h * dx5dt;
x(6,i)= x(6,i-1) + h * dx6dt;
end
tot=cell2mat(f); % Total fuel consumption during mission [kg/min]
Tot_fuel=sum(tot);
figure(1)
plot3(x1(:),x2(:),x3(:)); % 3D position graph
figure(2)
plot(t,x4(:)); % Vtas − Time graph
figure(3)
plot(t,V_ver(:)); % V_vertical − Time graph
figure(4)
plot(t,x5(:)); % Heading − Time graph
figure(5)
plot(t,x6(:)); % Mass − Time graph
figure(6)
plot(t,u1(:)); % Thrust − Time graph
figure(7)
plot(t,u2(:)); % Bank Angle − Time graph
figure(8)
plot(t,u3(:)); % Flight Path Angle − Time graph
fprintf('Total fuel consumption during mission is %.2f [kg]',Tot_fuel*tend/60);
I got this error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-79201.
Error in Flight (line 136)
x(1,i)= x(1,i-1) + h * dx1dt;
dx1dt is the 1-by-79201 one there. Is it because I have set the output lenghts of aforementioned functions in seperate tabs as linspace(H1,H2,79201)? If yes what should I hange, if no what should I do? 79201 is the length of t. Before doing that I have faced with array size problems. I am open to better suggestions.
2) With these lines I've tried to state that altitude [x(3,i-1)] remains constant:
elseif and (x(3,i-1) > 5249.3,x(3,i-1)<=5249.3) % Perform cruise flight for t=60 minutes.
and to state descent:
elseif and (x(3,i-1) < 3608.9,x(3,i-1)>=2624.67) % Descent to h3=800 [m] with κ=4.5◦ flight path angle.
Are they correct? If no, can you provide the corrected versions?
Thanks.
3 个评论
Torsten
2022-1-3
编辑:Torsten
2022-1-3
I mean:
Instead of setting
H_climb = linspace(H1,H2,79201);
in "Velocities", simply set
H_climb = x3
where x3 is your solution for the altitude at time t(i-1) (thus one single value).
This will return one single value for x4.
Same for the other deduced model variables x5, f, u1, u2, u3, C_D, Cl and p.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Aerospace Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!