How do I specify parameters to send to my ODE function when calling it using ode45?
Mostrar comentarios más antiguos
I'm trying to write a general function to propagate an orbit from initial position and velocity vectors using ode45, but I want to be able to specify mu in the script from which I call the funtion (via ode45).
Here is the function I'm propagating:
function [xdot] = RVorbitPropogation(t, x)
r = sqrt((x(1))^2 + (x(2))^2 + (x(3))^2); %Define R
xdot = [x(4); x(5); x(6); -(mu/((r)^3))*x(1); -(mu/((r)^3))*x(2); -(mu/((r)^3))*x(3); mu;]; %Define equation
end
I want to specify mu in the script so I can use this function for different bodies. Here is where I call the function:
[R_converted,V_converted] = oe2rv(oe, mu);
y0 = [R_converted(1), R_converted(2), R_converted(3), V_converted(1), V_converted(2), V_converted(3)];
[T, Y] = ode45(@RVorbitPropogation,tspan, y0);
Is there a way to add another input to ODE45 for mu? I've tried using
function [xdot] = RVorbitPropogation(t, x, mu)
r = sqrt((x(1))^2 + (x(2))^2 + (x(3))^2); %Define R
xdot = [x(4); x(5); x(6); -(mu/((r)^3))*x(1); -(mu/((r)^3))*x(2); -(mu/((r)^3))*x(3); mu;]; %Define equation
end
and
[R_converted,V_converted] = oe2rv(oe, mu);
y0 = [R_converted(1), R_converted(2), R_converted(3), V_converted(1), V_converted(2), V_converted(3)];
[T, Y] = ode45(@RVorbitPropogation,tspan, y0);
but that doesn't work because of the way ode45 understands inputs. Thanks for the help!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!