4th Order Runge Kutta using Numerical Integration
44 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am running this code to help me calculate the state space derivatives of an F-18 simulation, right my full code file runs and outputs graphs but I am not getting any data displayed, i believe my issue is stemming from the runge-kutta numerical integration function I built. Any help or suggestion on how to fix this or where I might have gone wrong.
function [t,x_sv_array,u_veh] = num_integration(t, x_sv_array, u_veh)
X = x_sv_array;
U_vec = u_veh;
hrzt = u_veh(1);
ail = u_veh(2);
rdr = u_veh(3);
flaple = u_veh(4);
spbr = u_veh(5);
thrtl = u_veh(6);
t0 = 0;
dt = 0.1;
t2 = 10;
t_hrzt_tab = [t0 t2].';
t_ail_tab = [t0 t2].';
t_rdr_tab = [t0 t2].';
t_flaple_tab = [t0 t2].';
t_spbr_tab = [t0 t2].';
t_thrtl_tab = [t0 t2].';
u_hrzt_tab = [hrzt hrzt ].';
u_ail_tab = [ail ail ].';
u_rdr_tab = [rdr rdr ].';
u_flaple_tab = [flaple flaple].';
u_spbr_tab = [spbr spbr ].';
u_thrtl_tab = [thrtl thrtl ].';
hrzt = interp1(t_hrzt_tab, u_hrzt_tab,t);
ail = interp1(t_ail_tab, u_ail_tab,t);
rdr = interp1(t_rdr_tab, u_rdr_tab,t);
flaple = interp1(t_flaple_tab, u_flaple_tab,t);
spbr = interp1(t_spbr_tab, u_spbr_tab,t);
thrtl = interp1(t_thrtl_tab, u_thrtl_tab,t);
u_veh = [hrzt ail rdr flaple spbr thrtl].';
f = airplane_coefficients(X,U_vec);
y = x_sv_array + f*dt/3;
z = x_sv_array + f*dt/2;
hrzt = interp1(t_hrzt_tab, u_hrzt_tab,t);
ail = interp1(t_ail_tab, u_ail_tab,t);
rdr = interp1(t_rdr_tab, u_rdr_tab,t);
flaple = interp1(t_flaple_tab, u_flaple_tab,t);
spbr = interp1(t_spbr_tab, u_spbr_tab,t);
thrtl = interp1(t_thrtl_tab, u_thrtl_tab,t);
u_veh = [hrzt ail rdr flaple spbr thrtl].';
f = airplane_coefficients(X,U_vec);
y = y + f*dt/3;
z = x_sv_array + f*dt/2;
hrzt = interp1(t_hrzt_tab, u_hrzt_tab,t);
ail = interp1(t_ail_tab, u_ail_tab,t);
rdr = interp1(t_rdr_tab, u_rdr_tab,t);
flaple = interp1(t_flaple_tab, u_flaple_tab,t);
spbr = interp1(t_spbr_tab, u_spbr_tab,t);
thrtl = interp1(t_thrtl_tab, u_thrtl_tab,t);
u_veh = [hrzt ail rdr flaple spbr thrtl].';
f = airplane_coefficients(X,U_vec);
y = y + f*dt/3;
z = x_sv_array + f*dt/2;
t = t + dt/2;
hrzt = interp1(t_hrzt_tab, u_hrzt_tab,t);
ail = interp1(t_ail_tab, u_ail_tab,t);
rdr = interp1(t_rdr_tab, u_rdr_tab,t);
flaple = interp1(t_flaple_tab, u_flaple_tab,t);
spbr = interp1(t_spbr_tab, u_spbr_tab,t);
thrtl = interp1(t_thrtl_tab, u_thrtl_tab,t);
u_veh = [hrzt ail rdr flaple spbr thrtl].';
f = airplane_coefficients(X,U_vec);
x_sv = y + f*dt/6;
return
end
6 Kommentare
Torsten
am 17 Dez. 2025 um 20:07
Bearbeitet: Torsten
am 18 Dez. 2025 um 2:22
I arranged your code in some way (see above), but I cannot understand how it's meant to work.
E.g. in num_integration, you compute
u_veh = [hrzt ail rdr flaple spbr thrtl].';
several times, but never use it because you call
f = airplane_coefficients(X,U_vec);
with U_vec instead of u_veh.
Further, you define
t0 = 0;
tf = 1;
dt = 0.1;
t = (t0:dt:tf);
in the script part, pass "t" to function "num_integration", but redefine
t0 = 0;
dt = 0.1;
t2 = 10;
therein.
Antworten (1)
Ritam
vor etwa 7 Stunden
Assuming your supporting functions are correct, the core issue appears to be in the 4th Runge-Kutta's method implementation: you compute
f = airplane_coefficients(X, U_vec)
four times with effectively the same state and control inputs. In classical fourth‑order Runge–Kutta's method, each of the four slopes must be evaluated at different intermediate states and times, using updated inputs derived from the preceding slope
k1 at (t,X,u(t))
k2 at (t+dt2,X+dt2k1,u(t+dt2))
k3 at (t+dt2,X+dt2k1,u(t+dt2))
k4 at (t+dt,X+dt k3,u(t+dt))
As a result, you should adjust the calls to "airplane_coefficients" so that each evaluation uses the appropriate intermediate state and time‑aligned control vector (rather than the initial X and U_vec). Making this change will align your integrator with RK4’s scheme and should resolve the “no data displayed” symptom by producing nontrivial state updates. Additionally, ensure the returned state is assigned back to your output (e.g., X_next into x_sv_array), and verify vector shapes (column orientation) to avoid silent plotting issues.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!