Mission 1
Names: James Li
ID: 29683750
clear all; close all; clc;
%% Student details
% Name: James Li
% ID: 29683750
%% Constants Required
Isp = 350; % Thrust of the engine used
g0 = 9.81; % Acceleration due to gravity
mass_initial = 60000; % Initial mass of the
spacecraft
k2_sun = 1.327*10^11; % k^2 value of the Sun
k2_earth = 3.986*10^5; % k^2 value at Earth
k2_saturn = 3.790561*10^7; % k^2 value at Saturn
R_earth = 149.6*10^6; % Radius of the orbit of
Earth around the Sun
R_saturn = 1.429*10^9; % Radius of the orbit of
Saturn around the Sun
r_earth = 6678; % Radius of Earth
r_saturn = 58232; % Radius of Saturn
%% Functions
% Finding velocity at a point(Vis-Viva equation)
V = @(k2,r,a) sqrt(2*k2)*sqrt(1/(r)-1/(2*a));
% Percentage of mass
P = @(deltaV,Isp,g0) 1 - exp(-deltaV/(Isp*g0));
DeltaV_reversed = @(p,Isp,g0) -Isp*g0*log(1-p);
% Finding apogee of ellipse
Apogee_ellipse = @(r,k2,v) r/2 + k2/(v^2);
% Finding time taken
Time = @(k2,a) (2*pi)/(sqrt(k2))*(sqrt(a^3));
% Finding eccentricity
Eccentricity = @(ra,rp) (ra-rp)/(ra+rp);
% Eccentricity anomaly
Eccentricity_anomaly = @ (e,theta) 2*atan(sqrt((1-
e)/(1+e)*tan(theta/2)));
%Aiming radius
Aiming_radius =@(Eccentricity)
Apogee_ellipse*sqrt(Eccentricity^1 - 1);
% Time within one orbit given a theta
Time_within = @(Me,period) Me*period/(2*pi);
% Finding theta
Theta = @ (h,k2,r,e) acos(h^2/(r*e*k2)-1/e);
% Function to solve the change in velocity (Hohmann
transfers)
DeltaV = @(k2,r1,r2)
sqrt(k2/r1)*(sqrt((2*r2)/(r1+r2))-1);
DeltaV_B = @(k2,r1,r2) sqrt(k2/r2)*(1-
sqrt(2*r1/(r1+r2)));
% Function to solve the required delta v to create
a certain vinfinity
DeltaV_parabolic = @(k2,rp,v_inf,v_circ)
sqrt(k2/rp)*(sqrt(2+(v_inf/v_circ)^2)-1);
%% Leaving Earth
% Delta v to reach Saturn from earth's orbit of the
sun also v infinity
deltaV1 = DeltaV(k2_sun,R_earth,R_saturn);
% V at perigee of earth (circular)
V_circ_earth = V(k2_earth,r_earth,r_earth);
% Required delta v to leave earth and intercept
with Saturn
V_leaving =
DeltaV_parabolic(k2_earth,r_earth,deltaV1,V_circ_ea
rth);
% mass used to leave earth
m = P(V_leaving*10^3,Isp,g0);
mass = mass_initial - m*mass_initial;
%% Finding the worst case scenario ellipse orbit of
Saturn
% Delta v or v infinity at Saturn
v_inf_saturn = DeltaV_B(k2_sun,R_earth,R_saturn);
% Finding apogee of parabolic
a_parabolic = 2*(k2_saturn/(v_inf_saturn)^2) +
r_saturn +100;
% Maximum delta V based on how much mass is left
p_fuel = (mass_initial-10500-
m*mass_initial)/(mass); %Percentage of fuel that is
left
allowable_deltaV =
DeltaV_reversed(p_fuel,Isp,g0)*10^-3;
% finding the corresponding velocity at perigee of
this "worst" case
velocity_perigee_ellipse_min =
V(k2_saturn,r_saturn+100,a_parabolic) -
allowable_deltaV;
ra_values
=abs(Apogee_ellipse(r_saturn+100,k2_saturn,velocity
_perigee_ellipse_min)); % Finding the corresponding
minimum apogee value
%Finds all delta V values to get into orbit
deltaV_values = zeros(1,length(ra_values));
mass_burned = zeros(1,length(ra_values));
available_mass = zeros(1,length(ra_values));
velocity_parabolic_perigee =
V(k2_saturn,100+r_saturn,a_parabolic); % Velocity
of parabolic orbital at perigee
% Finds the available mass for equipment
for i = 1:length(ra_values)
deltaV_values(i) =
abs(V(k2_saturn,100+r_saturn,ra_values(i)) -
velocity_parabolic_perigee); % Finds delta V of
each apogee value
mass_burned(i) = P(deltaV_values(i),Isp,g0)*mass;
% Finds the mass burned due to the delta V
available_mass(i) = mass_initial - mass_burned(i)
- 10500 - m*mass_initial; % Finds the available
mass for each case
end
%% Finding theta inside of 300km altitude
h_ellipse = zeros(1,length(ra_values));
e_ellipse = zeros(1,length(ra_values));
theta_ellipse = zeros(1,length(ra_values));
for i = 1:length(ra_values)
h_ellipse(i) = V(k2_saturn,r_saturn +
300,ra_values(i))*(r_saturn+300); % Specific
angular momentum
e_ellipse(i) =
Eccentricity(ra_values(i),r_saturn+100); %
Eccentricity of the apogee
theta_ellipse(i) =
Theta(h_ellipse(i),k2_saturn,300+r_saturn,e_ellipse
(i)); % The theta value of the spacecraft at 300km
altitude in the orbit
end
%% Finding time within altitude
period = zeros(1,length(ra_values));
E = zeros(1,length(ra_values));
Me = zeros(1,length(ra_values));
time_total = zeros(1,length(ra_values));
time_transfer = Time(k2_sun,R_saturn)/2; % Time
taken of the hohmann transfer
for i = 1:length(ra_values)
period(i) = 2*Time(k2_saturn,ra_values(i)); %
Orbital period of the ellipse
E(i) =
Eccentricity_anomaly(e_ellipse(i),theta_ellipse(i))
; % The Eccentricity anomaly of the theta
Me(i) = E(i) - e_ellipse(i)*sin(E(i)); % The mean
anomaly of the theta
time_total(i) = 0.35*Time_within(Me(i),period(i));
% Time that the spacecraft is inside a 300km
altitude
end
%% Maximum mass available
Max_mass= abs(available_mass(i)*2.16)
Mission 2
Name: James Li
ID: 29683750
clear all; close all; clc;
%% student details
% Name: James Li
% ID: 29683750
%% Constants Required
Isp = 350; % Thrust of the engine used
g0 = 9.81; % Acceleration due to gravity
mass_initial = 60000; % Initial mass of the
spacecraft
k2_sun = 1.327*10^11; % k^2 value of the Sun
k2_earth = 3.986*10^5; % k^2 value at Earth
k2_mars = 42.8*10^3; % k^2 value at Mars
R_earth = 149.6*10^6; % Radius of the orbit of
Earth aroundthe Sun
R_mars = 227.9*10^6; % Radius of the orbit of Mars
around theSun
r_earth = 6678; % Radius of Earth
r_mars = 3396; % Radius of mars
%% Functions
% Finding velocity at a point(Vis-Viva equation)
V = @(k2,r,a) sqrt(2*k2)*sqrt(1./(r)-1./(2*a));
% Percantage of mass
P = @(deltaV,Isp,g0) 1 - exp(-deltaV/(Isp*g0));
% Finding apogee of ellipse
Apogee_ellipse = @(r,k2,v) r/2 + k2/(v^2);
% Finding time taken
Time = @(k2,a) (2*pi)/(sqrt(k2))*(sqrt(a^3));
% Function to solve the change in velocity (Hohmann
transfers)
DeltaV = @(k2,r1,r2)
sqrt(k2/r1)*(abs(sqrt((2*r2)./(r1+r2))-1));
% Function to solve the required delta v to create
a certain vinfinity
DeltaV_parabolic = @(k2,rp,v_inf,v_circ)
sqrt(k2./rp).*(sqrt(2+(v_inf./v_circ).^2)-1);
% Finding apogee of hyperbolic
Apogee = @(h,k2,e) h^2/k2*(1/(e^2-1));
% Finding eccentricity
e = @(ra,rp) (ra-rp)/(ra+rp);
% Eccentricity anomaly
e_a = @ (e,theta) 2*atan(sqrt((1-
e)/(1+e)*tan(theta/2)));
% Finding velocity at periapsis for an ellipse
based on eccentricity
Velocity_ellipse = @(k2,r,e) sqrt(k2/r)*sqrt(1 +
e);
%% Leaving Earth
% Delta v to reach mars from earth's orbit of the
sun also vinfinity
v_inf_earth = DeltaV(k2_sun,R_earth,R_mars);
% V at perigee of earth (circular)
V_circ_earth = V(k2_earth,r_earth,r_earth);
% Required delta v to leave earth and intercept
with mars
v_leaving
=DeltaV_parabolic(k2_earth,r_earth,v_inf_earth,V_ci
rc_earth);
a_hyperbolic_earth = 2*(k2_earth/(v_inf_earth)^2) +
r_earth +300;
time_hyperbolic_earth =
(Time(k2_earth,a_hyperbolic_earth))/2;
% mass after leaving earth
percentage_mars = P(v_leaving*10^3,Isp,g0);
mass = mass_initial-(percentage_mars*mass_initial);
%% Finding the required delta v to be captured at
mars
% Delta v or v infinity at mars
v_inf_mars = DeltaV(k2_sun,R_mars,R_earth);
% Find the velocity in orbit around mars of an
eclipse with eccentricity
velocity_ellipse =
Velocity_ellipse(k2_mars,(150+r_mars),0.9);
% Find the delta v required to capture the
spacecraft
v_capture
=DeltaV_parabolic(k2_mars,(150+r_mars),v_inf_mars,v
elocity_ellipse) - 0.1;
%Transfer from ellipse to circular
velocity_circular =
V(k2_mars,(150+r_mars),(150+r_mars));
periods_to_circular = round(abs((velocity_circular
- velocity_ellipse)/0.1));
% Finding velocity of the parabolic at perigee
a_parabolic = 2*(k2_mars/(v_inf_mars)^2) + r_mars +
100;
velocity_parabolic_perigee
=V(k2_mars,100+r_mars,a_parabolic);
% Time spent in orbits
total_time = 0;
% First ellipse is special due to greater delta V
v_ellipse_perigee = (velocity_parabolic_perigee -
(v_capture +0.1));% Find velocity of the first
ellipse
a_ellipse =
Apogee_ellipse(r_mars+100,k2_mars,v_ellipse_perigee
);
orbital_first = Time(k2_mars,a_ellipse);
for i = 1:periods_to_circular-1
v_ellipse_perigee = (v_ellipse_perigee - 0.1);%
Find velocity of the ellipses after the first
a_ellipse =
Apogee_ellipse(r_mars+100,k2_mars,v_ellipse_perigee
);
orbital = Time(k2_mars,a_ellipse);% Find orbital
periodbased on this
total_time =+ orbital;% iterate to the next
ellipse whileadding up the time
end
time_hyperbolic_mars = Time(k2_mars,a_parabolic)/2;
% Total time of all the orbits
total_time_orbits = total_time + orbital_first +
time_hyperbolic_mars;
% Total time spent in orbit and landed on mars
total_time_all = total_time_orbits +
(250*24*60*60);
% Time for hohmann transfer to mars
transfer_time = Time(k2_sun,(R_mars+R_earth)/2)/2;
% mass after beginning orbit of mars
percentage_capture = P(v_capture*10^3,Isp,g0);
mass_mars = mass-(percentage_capture*mass);
time_mission = transfer_time*2 + total_time_all +
time_hyperbolic_earth + time_hyperbolic_mars
%% Flying back to Earth
% Velocity required to leave mars is the delta v of
the transfer
v_leaving_mars = DeltaV(k2_sun,R_mars,R_earth);
% aerobraking at Earth (km/s)
v_aerobraking_earth = 0.2;
percentage_mars = P(v_leaving_mars*10^3,Isp,g0);
percentage_earth =
P(v_aerobraking_earth*10^3,Isp,g0);
%% Calculatating eccentricity in order to find out
%number of passages through perigee in order to
achieve circular orbit around earth
ra = 6528;
rp2 = 2.7*10^4;
ra_values = [ra:rp2];
n = 1
h_ellipse = zeros(1,length(ra_values));
e_ellipse = zeros(1,length(ra_values));
theta_ellipse = zeros(1,length(ra_values));
for n = 1:length(ra_values);
n = n+1
h_ellipse(n) = V(k2_mars,r_mars +
100,ra_values(n))*(r_mars+100); % Specific angular
momentum
e_ellipse(n) = e(ra_values(n),r_mars+100);
if e_ellipse < 0
fprintf('\n number of passages through
perigee is %0.1f',e(n))
end
end