I need help with my MATLAB code. I am trying to create an orbit with the given kepler elements. But I am having a hard time plotting the orbit around the earth. When I try to plot the 3-D Orbit with this code, all I get is a sphere. I want to see a graph with the sphere and the orbit around it. Can you help me with this?   % Given parameters omega_earth = rad2deg(7.2921151467e-5); % Earth's rotational rate in deg/s period_of_repetition = 1 / 2; % Two orbits per day % Orbital parameters ecc = 0.74; i = 63.4349;                 % Inclination (deg) RAAN = -86.915798;           % RAAN (deg) argp = 270;                  % Arg_of_Perigee (deg) f = linspace(0, 360, 100);   % True anomaly (deg) mu = 398600.4418;            % gravitational parameter of Earth (km^3/s^2) % Calculate semi-major axis a = ((omega_earth * period_of_repetition) / (360))^(-2/3)   % km % Calculate periapsis and apoapsis distances periapsis_distance = a * (1 - ecc);    % km apoapsis_distance = a * (1 + ecc);     % km % Display the results disp(['Semi-Major Axis: ' num2str(a) ' meters']); disp(['Periapsis Distance: ' num2str(periapsis_distance) ' meters']); disp(['Apoapsis Distance: ' num2str(apoapsis_distance) ' meters']);   % Calculate orbital radius evolution with time r = a * (1 - ecc^2) ./ (1 + ecc * cosd(f)); % Calculate Cartesian coordinates (position and velocity) x = r .* (cosd(RAAN) * cosd(argp + f) - sind(RAAN) * sind(argp + f) * cosd(i)); y = r .* (sind(RAAN) * cosd(argp + f) + cosd(RAAN) * sind(argp + f) * cosd(i)); z = r .* (sind(argp + f) * sind(i)); v = sqrt(mu ./ r); % velocity magnitude vx = v .* (-sind(RAAN) * cosd(argp + f) - cosd(RAAN) * sind(argp + f) * cosd(i)); vy = v .* (cosd(RAAN) * cosd(argp + f) - sind(RAAN) * sind(argp + f) * cosd(i)); vz = v .* (cosd(argp + f) * sind(i)); % Plot orbital radius evolution figure; plot(f, r); xlabel('True Anomaly (rad)'); ylabel('Orbital Radius (km)'); title('Orbital Radius Evolution'); % Plot 3D orbit figure; plot3(x, y, z); hold on; % Plot the Earth as a simple sphere earth_radius = 6.371e3; % Earth's radius in meters [x_earth, y_earth, z_earth] = sphere; earth = surf(x_earth * earth_radius, y_earth * earth_radius, z_earth * earth_radius); colormap([0 0 1]); % Set the color to blue for Earth alpha(earth, 0.7); % Set transparency for Earth % Set equal axis scale axis equal; % Set labels and title xlabel('X (meters)'); ylabel('Y (meters)'); zlabel('Z (meters)'); title('3D Representation of the Orbit with Earth'); % Display the plot hold off;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help with my MATLAB code. I am trying to create an orbit with the given kepler elements. But I am having a hard time plotting the orbit around the earth. When I try to plot the 3-D Orbit with this code, all I get is a sphere. I want to see a graph with the sphere and the orbit around it. Can you help me with this?

 

% Given parameters
omega_earth = rad2deg(7.2921151467e-5); % Earth's rotational rate in deg/s
period_of_repetition = 1 / 2; % Two orbits per day

% Orbital parameters
ecc = 0.74;
i = 63.4349;                 % Inclination (deg)
RAAN = -86.915798;           % RAAN (deg)
argp = 270;                  % Arg_of_Perigee (deg)
f = linspace(0, 360, 100);   % True anomaly (deg)
mu = 398600.4418;            % gravitational parameter of Earth (km^3/s^2)

% Calculate semi-major axis
a = ((omega_earth * period_of_repetition) / (360))^(-2/3)   % km

% Calculate periapsis and apoapsis distances
periapsis_distance = a * (1 - ecc);    % km
apoapsis_distance = a * (1 + ecc);     % km

% Display the results
disp(['Semi-Major Axis: ' num2str(a) ' meters']);
disp(['Periapsis Distance: ' num2str(periapsis_distance) ' meters']);
disp(['Apoapsis Distance: ' num2str(apoapsis_distance) ' meters']);

 


% Calculate orbital radius evolution with time
r = a * (1 - ecc^2) ./ (1 + ecc * cosd(f));

% Calculate Cartesian coordinates (position and velocity)
x = r .* (cosd(RAAN) * cosd(argp + f) - sind(RAAN) * sind(argp + f) * cosd(i));
y = r .* (sind(RAAN) * cosd(argp + f) + cosd(RAAN) * sind(argp + f) * cosd(i));
z = r .* (sind(argp + f) * sind(i));

v = sqrt(mu ./ r); % velocity magnitude
vx = v .* (-sind(RAAN) * cosd(argp + f) - cosd(RAAN) * sind(argp + f) * cosd(i));
vy = v .* (cosd(RAAN) * cosd(argp + f) - sind(RAAN) * sind(argp + f) * cosd(i));
vz = v .* (cosd(argp + f) * sind(i));

% Plot orbital radius evolution
figure;
plot(f, r);
xlabel('True Anomaly (rad)');
ylabel('Orbital Radius (km)');
title('Orbital Radius Evolution');

% Plot 3D orbit
figure;
plot3(x, y, z);
hold on;

% Plot the Earth as a simple sphere
earth_radius = 6.371e3; % Earth's radius in meters
[x_earth, y_earth, z_earth] = sphere;
earth = surf(x_earth * earth_radius, y_earth * earth_radius, z_earth * earth_radius);
colormap([0 0 1]); % Set the color to blue for Earth
alpha(earth, 0.7); % Set transparency for Earth

% Set equal axis scale
axis equal;

% Set labels and title
xlabel('X (meters)');
ylabel('Y (meters)');
zlabel('Z (meters)');
title('3D Representation of the Orbit with Earth');

% Display the plot
hold off;

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Single source shortest path
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education