How to compute eccentricity for elliptical

3 次查看(过去 30 天)
how to make matlab compute eccentricity for elliptical figure that I am creating. I am creating elliptical using numerical method. See code below and attached.
clear all
clc
%* Set initial position and velocity of the comet.
r0 = 1 ;
v0 = pi;
r = [r0 0]; v = [0 v0];
%* Set physical parameters (mass, G*M)
GM = 4*pi^2; % Grav. const. * Mass of Sun (au^3/yr^2)
mass = 1.; % Mass of comet
adaptErr = 1.e-4; % Error parameter used by adaptive Runge-Kutta
time = 0;
%* Loop over desired number of steps using specified
% numerical method.
nStep = 1000;
tau = 0.001;
for iStep=1:nStep
%* Record position and energy for plotting.
rplot(iStep) = norm(r); % Record position for polar plot
thplot(iStep) = atan2(r(2),r(1));
tplot(iStep) = time;
kinetic(iStep) = .5*mass*norm(v)^2; % Record energies
potential(iStep) = - GM*mass/norm(r);
% Euler-Cromer step
accel = -GM*r/norm(r)^3;
v = v + tau*accel;
r = r + tau*v;
time = time + tau;
unwrap_theta=unwrap(thplot);
if unwrap_theta(iStep) > 2*pi
break
end
end
%* Graph the trajectory of the comet.
figure(1); clf; % Clear figure 1 window and bring forward
q=polar(thplot,rplot,'-'); % Use polar plot for graphing orbit
xlabel('Distance (AU)'); grid;
  1 个评论
James Tursa
James Tursa 2017-2-6
Are you simply asking how to calculate eccentricity from your initial state vector r and v?

请先登录,再进行评论。

回答(1 个)

James Tursa
James Tursa 2017-2-6
  1 个评论
Mohammed  Alshehri
I am trying to find out if there is a function in matlab that can calculate the eccentricity from the figure or from theta and r coordinates

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by