I need help with programming in MATLAB. The following code transforms cartesian coordinates to the kepler elements. Can you give me the code for transforming kepler orbital elements to cartesian coordinates. The following code gives the 6 kepler elements. Transform those elements into cartesian coordinate that match the values under the Example Usage part of the code. Can you send a screenshot so I know the output of your code matches the input of the following code?   % Example usage: x = 1000;    y = 2000;    z = 3000;    vx = 4;      vy = -3;     vz = 2;      [a, ecc, inc, raan, argp, f] = cart2orb(x, y, z, vx, vy, vz); % Display the results disp(['Semi-Major Axis (a): ', num2str(a), ' km']); disp(['Eccentricity (ecc): ', num2str(ecc)]); disp(['Inclination (inc): ', num2str(inc), ' degrees']); disp(['Right Ascension of Ascending Node (raan): ', num2str(raan), ' degrees']); disp(['Argument of Perigee (argp): ', num2str(argp), ' degrees']); disp(['True Anomaly (f): ', num2str(f), ' degrees']);   function [a, e, inc, raan, argp, f] = cart2orb(x, y, z, vx, vy, vz)     % Gravitational constant for Earth (μ⊕)     mu = 398600.4418;  % km^3/s^2     % Calculate position and velocity vectors     r = [x; y; z];         % Position vector     v = [vx; vy; vz];       % Velocity vector     % Calculate orbital parameters     h = cross(r, v);        % Specific angular momentum vector     n = cross([0; 0; 1], h); % Nodal vector     % Eccentricity (ecc)     e_vec = (cross(v,h)/mu) - (r/norm(r));     %e_vec = ((norm(v)^2 - mu/norm(r)) * r - dot(r, v) * v) / mu;     e = norm(e_vec);     % Semi-major axis (a)     a = (dot(h,h)/mu) / (1-e^2);     %a = 1 / (2/norm(r) - norm(v)^2/mu_earth);     % Inclination (inc)     inc = acosd(h(3) / norm(h));     % Right Ascension of Ascending Node (raan)     raan = atan2d(n(2), n(1));     raan = mod(raan + 360, 360);  % Ensure raan is in the range [0, 360)     % Argument of Perigee (argp)     argp = atan2d(dot(n, cross(e_vec, h)), dot(n, e_vec));     argp = mod(argp + 360, 360);  % Ensure argp is in the range [0, 360)     % True Anomaly (f)     f = atan2d(dot(e_vec, cross(h, r)), dot(e_vec, r));     f = mod(f + 360, 360);        % Ensure f is in the range [0, 360) end

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

I need help with programming in MATLAB. The following code transforms cartesian coordinates to the kepler elements. Can you give me the code for transforming kepler orbital elements to cartesian coordinates. The following code gives the 6 kepler elements. Transform those elements into cartesian coordinate that match the values under the Example Usage part of the code. Can you send a screenshot so I know the output of your code matches the input of the following code?

 

% Example usage:
x = 1000;   
y = 2000;   
z = 3000;   
vx = 4;     
vy = -3;    
vz = 2;     

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

% Display the results
disp(['Semi-Major Axis (a): ', num2str(a), ' km']);
disp(['Eccentricity (ecc): ', num2str(ecc)]);
disp(['Inclination (inc): ', num2str(inc), ' degrees']);
disp(['Right Ascension of Ascending Node (raan): ', num2str(raan), ' degrees']);
disp(['Argument of Perigee (argp): ', num2str(argp), ' degrees']);
disp(['True Anomaly (f): ', num2str(f), ' degrees']);

 

function [a, e, inc, raan, argp, f] = cart2orb(x, y, z, vx, vy, vz)
    % Gravitational constant for Earth (μ⊕)
    mu = 398600.4418;  % km^3/s^2

    % Calculate position and velocity vectors
    r = [x; y; z];         % Position vector
    v = [vx; vy; vz];       % Velocity vector

    % Calculate orbital parameters
    h = cross(r, v);        % Specific angular momentum vector
    n = cross([0; 0; 1], h); % Nodal vector

    % Eccentricity (ecc)
    e_vec = (cross(v,h)/mu) - (r/norm(r));
    %e_vec = ((norm(v)^2 - mu/norm(r)) * r - dot(r, v) * v) / mu;
    e = norm(e_vec);

    % Semi-major axis (a)
    a = (dot(h,h)/mu) / (1-e^2);
    %a = 1 / (2/norm(r) - norm(v)^2/mu_earth);

    % Inclination (inc)
    inc = acosd(h(3) / norm(h));

    % Right Ascension of Ascending Node (raan)
    raan = atan2d(n(2), n(1));
    raan = mod(raan + 360, 360);  % Ensure raan is in the range [0, 360)

    % Argument of Perigee (argp)
    argp = atan2d(dot(n, cross(e_vec, h)), dot(n, e_vec));
    argp = mod(argp + 360, 360);  % Ensure argp is in the range [0, 360)

    % True Anomaly (f)
    f = atan2d(dot(e_vec, cross(h, r)), dot(e_vec, r));
    f = mod(f + 360, 360);        % Ensure f is in the range [0, 360)
end

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning