I need help with programming in MATLAB. I am trying to convert kepler elemnts to cartesian coordinates. The code works perfectly if my true anomaly only has one value. The problem occurs when true anomaly f is equal to 100 different points within 0 to 360 degrees. I get size errors. How do I get 100 different cartesian coordinates using the 100 f values.

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 programming in MATLAB. I am trying to convert kepler elemnts to cartesian coordinates. The code works perfectly if my true anomaly only has one value. The problem occurs when true anomaly f is equal to 100 different points within 0 to 360 degrees. I get size errors. How do I get 100 different cartesian coordinates using the 100 f values.

 

 

% 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;
inc = 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)
t = 0:99;

% 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


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

[x, y, z, vx, vy, vz] = kep2cart(a, ecc, inc, raan, argp, f)

 

 

function [x, y, z, vx, vy, vz] = kep2cart(a, ecc, inc, raan, argp, f)
    %=========================================================================%
    % FUNCTION: kep2cart
    % DESCRIPTION: Converts kepler orbital elements to cartesian coordiantes
    % INPUTS:
    %   > a = semi-major axis [km]
    %   > ecc = eccentricity
    %   > inc = inclination angle [degs]
    %   > raan = right ascension of the ascending node [degs]
    %   > argp = arguement of periapsis [degs]
    %   > f = true anomaly [degs]
    %
    % OUPUTS:
    %   > x = 1x1 position value in the x-direction [km] 
    %   > y = 1x1 position value in the y-direction [km]
    %   > z = 1x1 position value in the z-direction [km]
    %   > vx = 1x1 velocity value in the x-direction [km/s]
    %   > vy = 1x1 velocity value in the y-direction [km/s]
    %   > vz = 1x1 velocity value in the z-direction [km/s]
    %=========================================================================%
    

    % Gravitational parameter 
    mu = 398600.4418;  % (km^3/s^2)
    
    % Calculate angular momentum
    h = sqrt(a * (1-ecc^2)*mu);    % (km^2/s)
    
    % Calculate position and velocity in the periforcal frame
    r_w = ((h^2 / mu) / (1 + ecc * cosd(f))) .* [cosd(f), sind(f), 0];
    v_w = (mu / h) .* [-sind(f), ecc + cosd(f), 0];
    
    % Calculate the Rotational Matrix
    R1 = [cosd(-argp) -sind(-argp) 0;
          sind(-argp) cosd(-argp)  0;
               0           0       1];
    R2 = [1      0          0;
          0 cosd(-inc) -sind(-inc);
          0 sind(-inc) cosd(-inc)];
    
    R3 = [cosd(-raan) -sind(-raan) 0;
          sind(-raan) cosd(-raan)  0;
               0           0       1];
    
    % Calculate position vector
    r_rot = r_w * R1 * R2 * R3;
    
    % Calculate velocity vector
    v_rot = v_w * R1 * R2 * R3;
    
    % Define the cartesian coordinates
    x = r_rot(1);
    y = r_rot(2);
    z = r_rot(3);
    vx = v_rot(1);
    vy = v_rot(2);
    vz = v_rot(3);

end

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
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