How can I convert the cosine function I get into a circle?

2 visualizzazioni (ultimi 30 giorni)
Hi,
Im trying to plot a complete 2*pi orbit 500km about the earth. I have the code i am using shown below but it ends up plotting a cosine function as the tangent velocity remains only positive. I am pretty sure the rest of the code is fine.
I need hlep either convering a cosine plot into a circular plot or help ensuring the the velocity of the vehicle changes from + to - at pi.
I have also attached the mathamatical reentry dynamics equations
% myeqn file - script 1
function dv = myeqn(t, x)
alpha = 0; % starting AoA
%State vector, intial conditions deifined in run_myeqn
theta=x(4); %starting theta angle
r=x(3); %starting postion above earth
v_t=x(2); % tanget velocity
v_r=x(1); % radial velocity
gamma = tan(x(1)./x(2));
v=sqrt(v_t^2+v_r^2); % velocity vector
mu_e = 3.986e14;
Re=6371e3;
h = r-Re;
m=5000;
%[T, P, rho] = standard_atm(h);
%lift drag set to zero as we are only trying to orbit the earth. therefore no drag and lift.
L=0;
D=0;
%[L, D] = Lift_Drag(h, alpha, v, rho);
dv_r = (-(mu_e)/(r^2)) + ((v_t^2)/r) + ((1/m)*(-D*sin(gamma)+L*cos(gamma))); % radial accel equation
dv_t= -((v_r*v_t)/r) + 1/m*(-D*cos(gamma) - L*sin(gamma)); % tangent accel equation
dr = v_r;
dtheta = v_t/r;
dv=[dv_r dv_t dr dtheta]';
return
%run_myeqn - script 2
clc
clear
v0=[0, 7616.6, 6871e3, 0];
t0=0;
tend=5000;
tstep=1;
options=odeset('Events',@myEvent);
[t,v] = ode45(@myeqn, t0:tstep:tend, v0,options)
r = v(:,3);
theta = v(:,4);
v_t = v(:,2);
v_r = v(:,1);
plot (r, theta)
%hold on
%ang=0:0.01:2*pi;
%x2=6871e3*cos(ang);
%y2=6871e3*sin(ang);
%plot(x2, y2);

Risposta accettata

Steven Lord
Steven Lord il 22 Nov 2019
Instead of a plot I think you want a polarplot (assuming you're using release R2016a or later.)
  1 Commento
Bilal Arshed
Bilal Arshed il 22 Nov 2019
Modificato: Bilal Arshed il 22 Nov 2019
yeah im on R2019a! i tried polar plot and it worked but seems to spiral into the earth now. I have attached an image of it.
UPDATED: thanks i acutally managed to fix it, but suggesting a polarplot really helps!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by