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

조회 수: 2 (최근 30일)
Bilal Arshed
Bilal Arshed 2019년 11월 22일
편집: Bilal Arshed 2019년 11월 22일
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);

채택된 답변

Steven Lord
Steven Lord 2019년 11월 22일
Instead of a plot I think you want a polarplot (assuming you're using release R2016a or later.)
  댓글 수: 1
Bilal Arshed
Bilal Arshed 2019년 11월 22일
편집: Bilal Arshed 2019년 11월 22일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by