MATLAB Script used to Solve Problem
mu = 398600.5;
R = [5492 3984 2.956];
V = [-3.931 5.499 3.666];
r = norm(R);
v = norm(v);
H = cross(R,V);
h = norm(H);
I = [1; 0; 0];
J = [0; 1; 0];clc
K = [0; 0; 1];
n = cross(K,H);
E = -((cross(H,V))/mu) - (R/r);
e = norm(E);
a = (h^2) / (mu*(1-e^2));
i = acos(H(3) / h);
omega = acos(n(1) / norm(n));
if n(2) < 0
omega = (2* pi) - (acos(n(1)/norm(n)));
end
w = acos((n*E')/ (norm(n)*e));
if (E * K) < 0
w = (2*pi) - acos((n*E')/ (norm(n)*e));
end
f = acos((R*E') / (r*e));
if (R*V') < 0
f = (2*pi) - acos((R*E') / (r*e));
end
i_angle = rad2deg(i);
o_angle = rad2deg(omega);
w_angle = rad2deg(w);
f_angle = rad2deg(f);
fprintf('a = %.4f km\n', a);
fprintf('e = %.4f\n', e);
fprintf('i = %2.3f degrees\n', i_angle);
fprintf('omega = %2.3f degrees\n', o_angle);
fprintf('w = %2.3f degrees\n', w_angle);
fprintf('f = %2.3f degrees\n', f_angle);
total_time = 100 * 60;
time_step = 10 * 60;
num_steps = total_time / time_step;
r_vec = zeros(3, num_steps + 1);
v_vec = zeros(3, num_steps + 1);
r_vec(:,1) = R';
v_vec(:,1) = V';
for k = 1:num_steps
dt = k * time_step;
M = sqrt(mu / a^3) * dt;
E = M;
tol = 1e-6;
max_iter = 100;
iter = 0;
while iter < max_iter
E_new = M + e * sin(E);
if abs(E_new - E) < tol
break;
end
E = E_new;
iter = iter + 1;
end
% Compute True Anomaly
theta_t = 2 * atan(sqrt((1 + e) / (1 - e)) * tan(E / 2));
% Compute new position and velocity vectors
r_norm = a * (1 - e * cos(E));
r_t = r_norm * [cos(theta_t); sin(theta_t); 0];
v_t = sqrt(mu * (2 / r_norm - 1 / a)) * [-sin(theta_t); cos(theta_t) + e; 0];
% Rotate to original frame
Rz_Omega = [cos(omega), -sin(omega), 0; sin(omega), cos(omega), 0; 0, 0, 1];
Rx_i = [1, 0, 0; 0, cos(i), -sin(i); 0, sin(i), cos(i)];
Rz_w = [cos(w), -sin(w), 0; sin(w), cos(w), 0; 0, 0, 1];
r_t = Rz_Omega * Rx_i * Rz_w * r_t;
v_t = Rz_Omega * Rx_i * Rz_w * v_t;
r_vec(:,k+1) = r_t;
v_vec(:,k+1) = v_t;
end
fprintf('\n%-10s %-10s %-10s %-10s %-10s %-10s %-10s\n', 'Time (min)', 'Rx (km)', 'Ry (km)', 'Rz (km)',
'Vx (km/s)', 'Vy (km/s)', 'Vz (km/s)');
fprintf(repmat('-', 1, 80));
fprintf('\n');
for k = 1:(num_steps+1)
fprintf('%-10d %-10.4f %-10.4f %-10.4f %-10.4f %-10.4f %-10.4f\n', time_steps(k), r_vec(1,k),
r_vec(2,k), r_vec(3,k), v_vec(1,k), v_vec(2,k), v_vec(3,k));
end
Solution
Aid from AI