How to compute eccentricity for elliptical

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 日

0 投票

1 件のコメント

Mohammed  Alshehri
Mohammed Alshehri 2017 年 2 月 6 日
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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGeoscience についてさらに検索

タグ

質問済み:

2017 年 2 月 6 日

コメント済み:

2017 年 2 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by