Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
23 views6 pages

Assignment 1

The document contains MATLAB code for calculating and visualizing Hohmann transfer orbits between two circular orbits. It computes parameters such as circular velocities, time periods, semi-major axes, and velocity changes required for the transfer, and visualizes the orbits and burn points in a 3D plot. Two scenarios are presented, one for a transfer from a lower to a higher orbit and another for a reverse transfer from a higher to a lower orbit.

Uploaded by

shamma shehzadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Assignment 1

The document contains MATLAB code for calculating and visualizing Hohmann transfer orbits between two circular orbits. It computes parameters such as circular velocities, time periods, semi-major axes, and velocity changes required for the transfer, and visualizes the orbits and burn points in a 3D plot. Two scenarios are presented, one for a transfer from a lower to a higher orbit and another for a reverse transfer from a higher to a lower orbit.

Uploaded by

shamma shehzadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Question 2

MATLAB Code
clc;
clear all;
close all;

Re = 6378;
mu = 3.986*10^5;
r1 = 350 + Re;
r2 = 35786 + Re;

vc1= sqrt(mu/r1);
fprintf('Circular Velocity of home orbit: %.3f km/s\n', vc1 );
T1 = (2*pi*(r1)^(3/2))/(sqrt(mu));
hrs = floor(T1 / 3600); mins = floor(mod(T1, 3600) / 60); secs = mod(T1, 60);
fprintf('Time Period of Home Orbit: %d hrs %d mins %.2f secs\n', hrs, mins, secs);

vc2 = sqrt(mu/r2);
fprintf('Circular Velocity of target orbit: %.3f km/s\n', vc2 );
T2 = (2*pi*(r2)^(3/2))/(sqrt(mu));
hrs = floor(T2 / 3600); mins = floor(mod(T2, 3600) / 60); secs = mod(T2, 60);
fprintf('Time Period of Target Orbit: %d hrs %d mins %.2f secs\n', hrs, mins, secs);

rp = r1;
ra = r2;
a = (rp+ra)/2;
fprintf('Semi major axis: %d km\n', a)

vp=sqrt(mu*((2/rp)-(1/a)));
fprintf('Velocity at periapsis: %.3f km/s\n',vp)
delta_v1 = vp-vc1;
fprintf('1st burn: %.3f km/s \n', delta_v1)

va=sqrt(mu*((2/ra)-(1/a)));
fprintf('Velocity at apoapsis: %.3f km/s\n',va)
delta_v2 = vc2-va;
fprintf('2nd burn: %.3f km/s \n', delta_v2)

e = (ra-rp)/(ra+rp);
fprintf('Eccentricity: %.4f\n',e)

T = (pi*(a)^(3/2))/(sqrt(mu));
hrs = floor(T / 3600); mins = floor(mod(T, 3600) / 60); secs = mod(T, 60);
fprintf('Time for this maneuver: %d hrs %d mins %.2f secs\n', hrs, mins, secs);

Total = delta_v1 + delta_v2;


fprintf('Total change in velocity: %.4f km/s \n' ,Total)
theta = linspace(0, pi, 150); % Half-transfer orbit (0 to π)

% Define circular orbits


x_home = r1 * cos(linspace(0, 2*pi, 300));
y_home = r1 * sin(linspace(0, 2*pi, 300));

x_target = r2 * cos(linspace(0, 2*pi, 300));


y_target = r2 * sin(linspace(0, 2*pi, 300));

% Define elliptical transfer orbit (only half)


r_transfer = a * (1 - e^2) ./ (1 + e * cos(theta)); % Polar form
x_transfer = r_transfer .* cos(theta);
y_transfer = r_transfer .* sin(theta);

% Plot Earth
figure;
hold on; axis equal; grid on;
[xE, yE, zE] = sphere(50);
surf(Re * xE, Re * yE, Re * zE, 'FaceColor', 'b', 'EdgeColor', 'none'); % Earth

% Plot Initial Orbit


plot3(x_home, y_home, zeros(size(x_home)), 'g', 'LineWidth', 2);

% Plot Target Orbit


plot3(x_target, y_target, zeros(size(x_target)), 'r', 'LineWidth', 2);

% Plot Transfer Orbit (Only Half)


plot3(x_transfer, y_transfer, zeros(size(x_transfer)), 'm--', 'LineWidth', 2);

% Plot the Burn Points


plot3(r1, 0, 0, 'bo', 'MarkerSize', 8, 'MarkerFaceColor', 'b'); % First Burn at Periapsis
plot3(-r2, 0, 0, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r'); % Second Burn at Apoapsis

% Labels
xlabel('X (km)'); ylabel('Y (km)'); zlabel('Z (km)');
title('Hohmann Transfer Visualization (Half-Orbit)');
legend({'Earth', 'Home Orbit', 'Target Orbit', 'Transfer Orbit', '1st Burn (Periapsis)', '2nd Burn
(Apoapsis)'}, 'Location', 'best');

hold off;
Output:
Question 3
MATLAB CODE
clc;
clear all;
close all;

Re = 6378;
mu = 3.986*10^5;
r1 = 20000 + Re;
r2 = 1000 + Re;

vc1= sqrt(mu/r1);
fprintf('Circular Velocity of home orbit: %.3f km/s\n', vc1 );
T1 = (2*pi*(r1)^(3/2))/(sqrt(mu));
hrs = floor(T1 / 3600); mins = floor(mod(T1, 3600) / 60); secs = mod(T1, 60);
fprintf('Time Period of Home Orbit: %d hrs %d mins %.2f secs\n', hrs, mins, secs);

vc2 = sqrt(mu/r2);
fprintf('Circular Velocity of target orbit: %.3f km/s\n', vc2 );
T2 = (2*pi*(r2)^(3/2))/(sqrt(mu));
hrs = floor(T2 / 3600); mins = floor(mod(T2, 3600) / 60); secs = mod(T2, 60);
fprintf('Time Period of Target Orbit: %d hrs %d mins %.2f secs\n', hrs, mins, secs);

ra = r1;
rp = r2;
a = (rp+ra)/2;
fprintf('Semi major axis: %d km\n', a)

va=sqrt(mu*((2/ra)-(1/a)));
fprintf('Velocity at apoapsis: %.3f km/s\n',va)
delta_v1 = vc1-va;
fprintf('1st burn: %.3f km/s \n', delta_v1)

vp=sqrt(mu*((2/rp)-(1/a)));
fprintf('Velocity at periapsis: %.3f km/s\n',vp)
delta_v2 = vp-vc2;
fprintf('2nd burn: %.3f km/s \n', delta_v2)

e = (ra-rp)/(ra+rp);
fprintf('Eccentricity: %.4f\n',e)

T = (pi*(a)^(3/2))/(sqrt(mu));
hrs = floor(T / 3600); mins = floor(mod(T, 3600) / 60); secs = mod(T, 60);
fprintf('Time for this maneuver: %d hrs %d mins %.2f secs\n', hrs, mins, secs);
Total = delta_v1 + delta_v2;
fprintf('Total change in velocity: %.4f km/s \n' ,Total)

theta = linspace(pi, 2*pi, 150); % Half-transfer orbit (pi to 2pi)

% Define circular orbits


theta_full = linspace(0, 2*pi, 300);
x_home = r1 * cos(theta_full);
y_home = r1 * sin(theta_full);

x_target = r2 * cos(theta_full);
y_target = r2 * sin(theta_full);

% Define elliptical transfer orbit (only half)


r_transfer = a * (1 - e^2) ./ (1 + e * cos(theta)); % Polar form
x_transfer = r_transfer .* cos(theta);
y_transfer = -r_transfer .* sin(theta); % Flip the orbit to be above

% Plot Earth
figure;
hold on; axis equal; grid on;
[xE, yE, zE] = sphere(50);
surf(Re * xE, Re * yE, Re * zE, 'FaceColor', 'b', 'EdgeColor', 'none'); % Earth

% Plot Initial Orbit


plot3(x_home, y_home, zeros(size(x_home)), 'g', 'LineWidth', 2);

% Plot Target Orbit


plot3(x_target, y_target, zeros(size(x_target)), 'r', 'LineWidth', 2);

% Plot Transfer Orbit (Only Half) - Now Above!


plot3(x_transfer, y_transfer, zeros(size(x_transfer)), 'm--', 'LineWidth', 2);

% Plot the Burn Points


plot3(-r1, 0, 0, 'bo', 'MarkerSize', 8, 'MarkerFaceColor', 'b'); % First Burn on Left Side
plot3(r2, 0, 0, 'ro', 'MarkerSize', 8, 'MarkerFaceColor', 'r'); % Second Burn on Right Side

% Labels
xlabel('X (km)'); ylabel('Y (km)'); zlabel('Z (km)');
title('Reverse Hohmann Transfer (Transfer Orbit Above)');
legend({'Earth', 'Initial Orbit', 'Target Orbit', 'Transfer Orbit', '1st Burn (Apoapsis)', '2nd Burn
(Periapsis)'}, 'Location', 'best');

hold off;
Output

Scenario of Hohmann Transfer

You might also like