twobodyEOM: % ~~~~~~~~~~~~~~~~~~~~~~~~ function dYdt = twobodyEOM2D(t,Y,mu) % --
ID: 1884469 • Letter: T
Question
twobodyEOM:
% ~~~~~~~~~~~~~~~~~~~~~~~~
function dYdt = twobodyEOM2D(t,Y,mu)
% ------------------------
%{
This function calculates first and second time derivatives of r
governed by the equation of two-body 2D motion
Y - column vector containing r and v at time t
dYdt - column vector containing drdt and dvdt at time t
User M-functions required: none
%}
% ~~~~~~~~~~~~~~~~~~~~~~~~
rvec = Y(1:2);
vvec = Y(3:4);
r = sqrt(rvec(1)^2+rvec(2)^2) ;
rdotvec = vvec ;
vdotvec = -mu/r^3*rvec ;
dYdt = [rdotvec; vdotvec];
end
CALLTWOBODY:
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Example_1_20
% ~~~~~~~~~~~~~~~~~~~
%{
This program uses ode45 with adaptive step size control
to solve the 2D equations of motion of two-body motion
User subfunction required: twobodyEOM2D
%}
% ---------------------------------------------------------------------
clear all
close all
clc
% Initialize parameters
mu = 398600; % Earth gravitational parameter
% Initialize initial conditions
r0 = 6500 ; % initial radius, in km
v0 = 7.8309 ; % initial velocity, in km/s
r0vec = [r0; 0] ;
v0vec = [0; v0] ;
Y0 = [r0vec; v0vec];
% Integration time
t0 = 0;
tf = 86400; % 1 day (or 86400 s)
% Integration options
options = odeset('RelTol', 1e-8, 'AbsTol', 1e-8) ;
% call ode45
[T,Y] = ode45(@twobodyEOM2D, [t0 tf], Y0, options, mu);
% Plot radius over time
for k=1:length(T)
rvec = Y(k,1:2)' ;
radius(k) = norm(rvec) ;
end
figure(1)
plot(T/86400,radius)
xlabel('Time (in days)')
ylabel('orbit radius (in km)')
Explanation / Answer
What do you want to ask. I'm not getting it.
Plz write your question, as you have made a matlab program already.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.