Code covered by the BSD License  

Highlights from
Vectorized N-Body Equation

Be the first to rate this file! 7 Downloads (last 30 days) File Size: 3.81 KB File ID: #27820

Vectorized N-Body Equation

by Dmitry Savransky

 

02 Jun 2010

Fully vectorized n-body equations of motion in second and first order form.

| Watch this File

File Information
Description

NBODYVECT - Fully vectorized n-body equation
nbodyVect(x0,dx0,mus,t) integrates the n-body equations of motion using either a symplectic second order integrator, or any of the standard built-in or user supplied first order integrators.

     x0 - 3n x 1 stacked initial position vectors:
          [r1(1);r1(2);r1(3);r2(1);r2(2)r2(3);...;rn(1);rn(2);rn(3)]
     dx0 - 3n x 1 stacked initial velocity vectors
     mus - gravitational parameters (G*m_i) where G is the gravitational constant and m_i is the mass of the ith body.
     t - time span: either a 2 element array of initial and final time, or array of all time steps to output.

     All units must be complementary, i.e., if positions are in AUs, and time is in days, dx0 must be in AU/day and mus must be in AU^3/day^2 (these are the units in solarSystemData.mat). This data was downloaded from JPL's System Web Interface (http://ssd.jpl.nasa.gov/?horizons)

     To switch to first order integrator, comment line 61, and uncomment lines 64-65. Line 61 should be replaced with your symplectic integrator of choice, such as rkn86 (this needs modifications to accept arbitrary time arrays).

     Example:
     %integrate solar system for one year
     ssdat = load('solarSystemData.mat');
     [t,x,dx] = nbodyVect(ssdat.p0,ssdat.v0,ssdat.mus,0:1:365);
     %plot first 3 orbits
     plot3(x(:,1),x(:,2),x(:,3),x(:,4),x(:,5),x(:,6),x(:,7),...
          x(:,8),x(:,9))

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
rkn86

MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
mathematics Dmitry Savransky 02 Jun 2010 11:30:24
physics Dmitry Savransky 02 Jun 2010 11:30:24
aerospace Dmitry Savransky 02 Jun 2010 11:30:24
simulation Dmitry Savransky 02 Jun 2010 11:30:24

Contact us at files@mathworks.com