Integrates a state using ode113 and then extracts the last value of Xdot calculated by ode113 using the derivative function. Note that you need to have defined your initial state vector state and the parameter GM before running this code.
options = odeset('RelTol',1e-13,'AbsTol',1e-16);
state = [initial_position_and_velocity];
[t, listState] = ode113(@(t, state) derivative(t, state, GM), [0 1], state, options);
newState = listState(end,:);
Xdot_last = derivative(t(end), newState, GM);
disp('The last Xdot value is:');
function Xdot = derivative(~, X, GM)
Xdot = [X(4:6); -GM * X(1:3) / r^3];
- initial_position_and_velocity should be replaced with the actual initial state vector of your system, which is a six-element vector consisting of the initial position and velocity components.
- your_GM_value should be replaced with the actual value of the gravitational parameter (gravitational constant times the mass of the central body) for your problem.
The derivative function which calculates the rate of change of the state vector based on the current state and the gravitational parameter GM. The Xdot_last variable will contain the rate of change at the last time step after the integration is complete. Make sure that your state and GM variables are defined before running this code.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems
- Electrical and Electronics Engineering