satellite orbit in matlab

To plot a satellite orbit in MATLAB, you can use the following code snippet to create a simple simulation of the orbit. You can adjust the parameters such as the gravitational constant, satellite mass, initial position, and velocity to simulate different scenarios.

main.m
% Constants
G = 6.67430e-11;     % Gravitational constant
M = 5.972e24;        % Earth mass
R = 6.371e6;         % Earth radius

% Initial conditions
r0 = R + 500e3;      % Initial distance from Earth's center
v0 = 7000;           % Initial velocity

% Time span
tspan = [0 2*pi*sqrt((r0^3)/(G*M))]; % One orbit period

% Differential equation for satellite motion
f = @(t, y) [y(3); y(4); -G*M*y(1)/(sqrt(y(1)^2 + y(2)^2))^3; -G*M*y(2)/(sqrt(y(1)^2 + y(2)^2))^3];

% Solve differential equation
[t, y] = ode45(f, tspan, [r0; 0; 0; v0]);

% Plot satellite orbit
figure;
plot(y(:,1), y(:,2));
axis equal;
xlabel('x (m)');
ylabel('y (m)');
title('Satellite Orbit Simulation');
675 chars
26 lines

This code uses numerical integration with the ode45 function to solve the differential equations of motion for the satellite in orbit around the Earth. The f function defines the differential equations based on the gravitational force. The orbit is then plotted in a 2D plot.

You can run this code in MATLAB to visualize the satellite orbit. Feel free to customize the parameters and add more features to enhance the simulation.

related categories

gistlibby LogSnag