How to compute eccentricity for elliptical
3 views (last 30 days)
Show older comments
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 Comment
James Tursa
on 6 Feb 2017
Are you simply asking how to calculate eccentricity from your initial state vector r and v?
Answers (1)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!