Code covered by the BSD License  

Highlights from
A MATLAB Script for Predicting the Evolution of Lunar Orbits

A MATLAB Script for Predicting the Evolution of Lunar Orbits

by

 

Script for propagating lunar orbits subject to non-spherical lunar gravity and third-body gravity.

lplot.m
% lplot.m        February 21, 2013

% graphic display of lprop_matlab csv data files

% Orbital Mechanics with MATLAB

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear all;

clc; home;

% request name of data file

[filename, pathname] = uigetfile('*.csv', 'please select a data file');

% read csv data file

oedata = csvread(filename);

% initialize graphics "flag"

igraph = 1;

if (igraph == 1)
        
    while (1)
        
        while (1)
            
            % request item to plot
            
            fprintf('\n\nplease select the orbital element to plot\n');
            
            fprintf('\n  <1> semimajor axis\n');
            
            fprintf('\n  <2> orbital eccentricity\n');
            
            fprintf('\n  <3> orbital inclination\n');
            
            fprintf('\n  <4> argument of perigee\n');
            
            fprintf('\n  <5> right ascension of the ascending node\n');
            
            fprintf('\n  <6> true anomaly\n');
            
            fprintf('\n  <7> periapsis altitude\n');
            
            fprintf('\n  <8> apoapsis altitude\n\n');
            
            oetype = input('? ');
            
            if (oetype >= 1 && oetype <= 8)
                
                break;
                
            end
            
        end
        
        % request name of graphics disk file
        
        fprintf('\n\nplease input a name for the graphics disk file');
        fprintf('\n(be sure to include the filename extension)\n');
        
        plotfname = lower(input('? ', 's'));
        
        % extract time and orbital element data
        
        xdata = oedata(1:end, 1);
        
        ydata = oedata(1:end, oetype + 1);
        
        % create plot
        
        plot(xdata, ydata);
        
        switch oetype
            
            case 1
                
                ylabel('semimajor axis (kilometers)', 'FontSize', 12);
                
            case 2
                
                ylabel('orbital eccentricity', 'FontSize', 12);
                
            case 3
                
                ylabel('orbital inclination (degrees)', 'FontSize', 12);
                
            case 4
                
                ylabel('argument of perigee (degrees)', 'FontSize', 12);
                
            case 5
                
                ylabel('RAAN (degrees)', 'FontSize', 12);
                
            case 6
                
                ylabel('true anomaly (degrees)', 'FontSize', 12');
                
            case 7
                
                ylabel('periapsis altitude (kilometers)', 'FontSize', 12');
                
            case 8
                
                ylabel('apoapsis altitude (kilometers)', 'FontSize', 12);                
        end
        
        title('Long Term Evolution of Lunar Orbits', 'FontSize', 16);
        
        xlabel('simulation time (days)', 'FontSize', 12);
        
        grid;
        
        zoom on;
        
        % create eps file with tiff preview
         
        print ('-depsc', '-tiff', '-r300', plotfname);
        
        % create another plot?
        
        while (1)
            
            fprintf('\n\nwould you like to create another plot (y = yes, n = no)\n');
            
            yn = lower(input('? ', 's'));
            
            if (yn == 'y' || yn == 'n')
                
                break;
                
            end
            
        end
        
        if (yn == 'n')
            
            break;
            
        end
        
    end
end

disp(' ');

fclose('all');

Contact us