write an n-body orbit propagator that factors in drag and solar radiation pressure in matlab

One implementation of an n-body orbit propagator that accounts for both drag and solar radiation pressure is the Cowell's method. This method is implemented in many astrodynamics libraries such as the NASA GMAT, and can be implemented in MATLAB using the following steps:

  1. Define the initial conditions for the spacecraft (position, velocity, mass, etc.) and the gravitational elements of the central body (mu, J2, J3, etc.)

  2. Define the coefficient of drag (Cd) and the coefficient of solar radiation pressure (Cr) based on the characteristics of the spacecraft.

  3. Choose a numerical integrator for the propagation process (e.g., Runge-Kutta, Dormand-Prince, etc.) and set the integration step size.

  4. During each integration step, calculate the acceleration of the spacecraft due to the central body's gravity, drag, and solar radiation pressure.

  5. Update the position and velocity of the spacecraft based on the calculated acceleration, and update the mass of the spacecraft based on the fuel consumption.

Here's an example function that implements the Cowell's method:

main.m
function [t, r, v] = nbody_propagate_drag_srp(tspan, r0, v0, Cd, Cr, m0, mu, J2, J3, step)

% Define initial conditions
r = r0;
v = v0;
m = m0;

% Define constants
rho_0 = 3.614e-13; % kg/m^3, density at sea level
H = 8.5e3; % m, scale height
AU = 1.495978707e11; % m, astronomical unit
c = 2.998e8; % m/s, speed of light
pr = 4.57e-6; % N/m^2, solar radiation pressure at 1 AU

% Convert the Coefficients to SI Units
Cd = Cd * 1e-3;
Cr = Cr * pr / c;

% Define the acceleration function
function [a_drag, a_srp] = acceleration(r, v, t)
  % Calculate the atmospheric density
  h = norm(r) - 6378.137; % km, altitude
  rho = rho_0 * exp(-h / H);

  % Calculate the aerodynamic drag acceleration
  v_rel = v - cross([0;0;7.292115e-5], r); % m/s, relative velocity
  a_drag = -0.5 * rho * Cd * norm(v_rel) * v_rel / m;

  % Calculate the solar radiation pressure acceleration
  r_au = norm(r) / AU; % AU, distance from the Sun
  a_srp = -Cr * r_au^(-2) * r / norm(r) * (1 + 4 * J2 * (r(3) / norm(r))^2 * (1.5 * (r(1)^2 - r(2)^2) / norm(r)^2 - 0.5));
end

% Define the integration function
function [rdot, vdot, mdot] = dynamics(t, r, v, m)
  % Calculate the accelerations
  [a_drag, a_srp] = acceleration(r, v, t);
  a_grav = -mu * r / norm(r)^3;
  
  % Update the position and velocity
  rdot = v;
  vdot = a_grav + a_drag + a_srp;
  
  % Update the mass
  mdot = -Cd * rho_0 * norm(v - cross([0;0;7.292115e-5], r))^2 / (2 * pr) * norm(r) / AU^2;
end

% Propagate the orbit
options = odeset('RelTol', 1e-13, 'AbsTol', 1e-16);
[t, y] = ode45(@(t,y)dynamics(t, y(1:3), y(4:6), y(7)), tspan, [r; v; m], options);
r = y(:,1:3);
v = y(:,4:6);
m = y(:,7);
end
1652 chars
55 lines

This function takes the following inputs:

  • tspan: a vector containing the start and end times of the simulation and the desired step size (e.g., tspan = [0 86400 60] for a simulation from time 0 to 86400 seconds with a step size of 60 seconds)

  • r0: the initial position vector of the spacecraft

  • v0: the initial velocity vector of the spacecraft

  • Cd: the coefficient of aerodynamic drag of the spacecraft

  • Cr: the coefficient of solar radiation pressure of the spacecraft

  • m0: the initial mass of the spacecraft

  • mu: the gravitational parameter of the central body

  • J2, J3: the zonal harmonics of the central body

  • step: the integration step size (optional, defaults to 60 seconds)

And returns the following outputs:

  • t: a vector containing the simulation times

  • r: a matrix containing the position vectors of the spacecraft at each simulation time

  • v: a matrix containing the velocity vectors of the spacecraft at each simulation time

Note that the function assumes that the spacecraft is in a circular orbit around the central body at the start of the simulation, and that the central body is not affected by drag or solar radiation pressure. If these assumptions do not hold, additional modifications to the function may be necessary.

gistlibby LogSnag