MATLAB Answers


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

Asked by Bilal Arshed on 22 Nov 2019 at 13:31
Latest activity Edited by Bilal Arshed on 22 Nov 2019 at 23:25
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;
h = r-Re;
%[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, 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]';
%run_myeqn - script 2
v0=[0, 7616.6, 6871e3, 0];
[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
%plot(x2, y2);


Sign in to comment.

1 Answer

Answer by Steven Lord
on 22 Nov 2019 at 14:34
 Accepted Answer

Instead of a plot I think you want a polarplot (assuming you're using release R2016a or later.)

  1 Comment

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!

Sign in to comment.