SlideShare a Scribd company logo
1 of 6
Sultan LeMarc
Computational Physics

30/03/2012

The Two Dimensional Gravitational Problem
Objective
The aim of this project is to model the two-dimensional gravitational problem
by a program using the C++ language. The objective of this program is to read,
in two dimensions, the initial positions, velocities and masses of two bodies
and use Newton’s law of universal gravitation to calculate the two-dimensional
forces on each body.
It follows this by using Newton’s second law to calculate the acceleration of
the bodies in a given time frame in order to establish their movements of the
bodies. A file is generated by the program with the positions of both bodies at
each time step over a whole time period, which is then used to plot the paths
of the two bodies.
The two-body gravitational problem concerns the motion of two point masses
that interact only with each other due to gravity. Such models are
approximated commonly in the Universe, for example the Earth’s orbit around
the Sun, the moon’s orbit around the Earth, and two starts orbiting each other.
Newton’s Law of Universal Gravitation:
Newton published his work on the law of gravity in 1967, introducing the law
of universal gravitation, which states that every particle in the Universe
attracts every other particle with a force that is directly proportional to the
product of their masses and inversely proportional to the square of the
distance between them (Serway, 2010).
For two bodies, of masses m1 and m2(kg), separated by a distance r (m), the
magnitude of the gravitational force, in Newtons (N), is:

where G is a constant called the universal gravitational constant. In SI units, it’s
value is:
This is often referred to as the inverse-square law, as the force varies as the
inverse square of the separation of the bodies.
As the constant G is used throughout the program, it is declared as a fixed
variable by const double G=6.67300E-11.
The program makes use of 1D arrays of size [2] for the two-dimensional
components of positionpos_m[2], velocity vel_m[2], acceleration acc_m[2],
and force gforce_m[2]. Each mass is allocated an array for each of these
variables.
In order to find the distance that separates the two bodies, r, from the initial x
and y positions, the change in each component is used in:

This is coded as:

dx = pos_m2[0]-pos_m1[0]
dy = pos_m2[1]-pos_m1[1]
r = sqrt ((dx*dx)+(dy*dy))

This allows the gravitational force acting on each body by the other along the
line of action to be found. The two dimensional components of this force is
found using trigonometric principles. First, the program finds the angle
between the line of action and the x-axis by:

This is coded as angle=atan2(dy,dx);
This angle is then used to resolve the components of the calculated force:

Newton’s third law, which states that if two bodies interact, the force F12
exerted by body 1 on body 2 is equal in magnitude and opposite in direction to
the force F21 exerted by body 2 on body 1:

Therefore the program implements this by equating the component forces of
body 2 as the negative equivalents of the component forces of body 1:
gforce_m1[0] = F*cos(angle);
gforce_m1[1] = F*sin(angle);
gforce_m2[0] = -F*cos(angle);
gforce_m2[1] = -F*sin(angle);
The two dimensional acceleration is found from these forces by using
Newton’s second law, which states that the acceleration of an object is directly
proportional to the net force acting on it and inversely proportional to its mass
(Serway, 2010):
This is applied for each component of the forces for both bodies by:
ax1 = Fx1/m1:acc_m1[0] = gforce_m1[0]/m1;
ay1 = Fy1/m1:acc_m1[1] = gforce_m1[1]/m1
ax2= Fx2/m2: acc_m2[0] = gforce_m2[0]/m2;
ay2 = Fy2/m2: acc_m2[1] = gforce_m2[1]/m2;
The acceleration is used to find the change in velocity of each body in a given
time step, but first the time step ∆t is determined from the calculated period T.
The program assumes that the motion is an orbit. The period of the orbit is
determined by the consideration of orbital energy conservation, which
requires that the sum of kinetic and potential energies be constant at all points
in the motion. The equation for orbital energy conservation, also known as
“Vis-Viva” is:

wherevr is the relative velocity given by:

This is coded as:dv[0] = vel_m2[0]-vel_m1[0];
dv[1] = vel_m2[1]-vel_m1[1];
rel_vel = sqrt((dv[0]*dv[0])+(dv[1]*dv[1]));
The program uses this value to find orbital energy by:
orb_energy = (0.5*rel_vel*rel_vel)-(G*(m1+m2)/r);

This orbital energy acts as the condition which defines the type of orbit
experienced by the bodies:
 ϵ < 0: Elliptical orbit
This corresponds to the minimum and maximum values of r for an
elliptical orbit where the distances of closest and farthest approach are
equal to r0/1-ε.
 ϵ = 0: Parabolic orbit
This corresponds to the escape velocity condition as a body is outside
the bounds of another body’s gravitational force when energy is
equivalent to zero i.e.
.
 ϵ > 0: Hyperbolic orbit
(MIT.edu)
In a parabolic or hyperbolic trajectory the motion is not periodic, and the
duration of the full trajectory is infinite. Therefore the programprints an error
message and aborts program upon the result of a parabolic or hyperbolic orbit
when testing for the orbital energy conditions.
The semi-major axis is half of the major axis of an ellipse which has a length
from the centre to the edge of the ellipse along its principle axes. The orbital
energy is used to find the semi-major axis, a, of the elliptical orbit:

This is coded by sm_axis = -(G*(m1+m2))/(2*orb_energy).
With the semi-major axis value, the period T of the orbit is determined through
Kepler’s third law, which states that the square of the orbital period of a planet
is directly proportional to the cube of the semi-major axis of its orbit:

For this the value of π is declared as a fixed variable to 8 significant figures:
const double pi = 3.1415926;
The calculation for T is coded as:
T = sqrt(fabs((4*pi*pi*sm_axis*sm_axis*sm_axis)/(G*(m1+m2))));
The program determines the time step ∆t according to this calculated period
by setting
.

Having established the time step, the new velocities are found by accumulating
the change in velocity, as related by acceleration and the time:
.
As with acceleration, this is done for each of the components of velocity for
both bodies:
vel_m1[0] += acc_m1[0]*dt;
vel_m1[1] += acc_m1[1]*dt;
vel_m2[0] += acc_m2[0]*dt;
vel_m2[1] += acc_m2[1]*dt;
Finally, the new positions of the bodies are calculated using the following
equation of motion:

where s is the displacement and u is the initial velocity. As the calculation takes
within a for loop where the new velocity after each time step becomes the
initial velocity for the next and likewise with position, it is coded as:
pos_m1[0] += ((vel_m1[0]*dt)+(0.5*acc_m1[0]*dt*dt));
pos_m1[1] += ((vel_m1[1]*dt)+(0.5*acc_m1[1]*dt*dt));
pos_m2[0] += ((vel_m2[0]*dt)+(0.5*acc_m2[0]*dt*dt));
pos_m2[1] += ((vel_m2[1]*dt)+(0.5*acc_m2[1]*dt*dt));
The program prints the positions of both bodies into a 2D array, position, of
size[1001][4] and writes a spread sheet file for excel which can then be
plotted.
Assumptions
 The bodies are point particles; their sizes are negligible centre-to-centre
distance is not considered.
 If orbital energy is less than zero then orbiting body has two turning
points, rmin and rmax. Body gets no closer than rminto central body and no
further than rmax due to conservation of angular momentum.
 The gravitational fields of the bodies are uniform.
 The motion of the bodies as a result of the interaction is closed and
periodic i.e. elliptical or circular orbits. Open orbits of parabolic or
hyperbolic give void readings.
 The two bodies are isolated from the Universe, therefore do not
experience gravitational force from any other body i.e. only one central
force acting.
 Centre of mass of the isolated system is not accelerated.
 The larger of the two masses is stationary and fixed at the origin of the
system.
Figure 1: Plot of X-Y positions of two masses, calculated by program.

Program input values:
Mass 1: 2E30
Initial Position: 0, 0
Initial Velocity: 0, 0
Mass 2: 6E24
Initial Position: 1.496E11, 0
Initial Velocity: 0, 29E3

More Related Content

What's hot

Öncel Akademi: İstatistiksel Sismoloji
Öncel Akademi: İstatistiksel SismolojiÖncel Akademi: İstatistiksel Sismoloji
Öncel Akademi: İstatistiksel SismolojiAli Osman Öncel
 
Universal Gravitation
Universal GravitationUniversal Gravitation
Universal GravitationZBTHS
 
Accuracy of the internal multiple prediction when a time-saving method based ...
Accuracy of the internal multiple prediction when a time-saving method based ...Accuracy of the internal multiple prediction when a time-saving method based ...
Accuracy of the internal multiple prediction when a time-saving method based ...Arthur Weglein
 
Gravitational Fields
Gravitational FieldsGravitational Fields
Gravitational FieldsPaula Mills
 
Principles of soil dynamics 3rd edition das solutions manual
Principles of soil dynamics 3rd edition das solutions manualPrinciples of soil dynamics 3rd edition das solutions manual
Principles of soil dynamics 3rd edition das solutions manualHuman2379
 
Coordinate systems
Coordinate systemsCoordinate systems
Coordinate systemsAmeenSoomro1
 
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]AI Robotics KR
 
JC A Level H2 Physics Dynamics Notes
JC A Level H2 Physics Dynamics NotesJC A Level H2 Physics Dynamics Notes
JC A Level H2 Physics Dynamics NotesJohn Jon
 
1.1.1 gravitational fields
1.1.1   gravitational fields1.1.1   gravitational fields
1.1.1 gravitational fieldsJohnPaul Kennedy
 
Earth 0205-response spectrum
Earth 0205-response spectrumEarth 0205-response spectrum
Earth 0205-response spectrumtharwat sakr
 
Work energy theorem summary 7 may 2015
Work energy theorem summary 7 may 2015Work energy theorem summary 7 may 2015
Work energy theorem summary 7 may 2015Mphiriseni Khwanda
 

What's hot (20)

hw2
hw2hw2
hw2
 
Öncel Akademi: İstatistiksel Sismoloji
Öncel Akademi: İstatistiksel SismolojiÖncel Akademi: İstatistiksel Sismoloji
Öncel Akademi: İstatistiksel Sismoloji
 
Universal Gravitation
Universal GravitationUniversal Gravitation
Universal Gravitation
 
Accuracy of the internal multiple prediction when a time-saving method based ...
Accuracy of the internal multiple prediction when a time-saving method based ...Accuracy of the internal multiple prediction when a time-saving method based ...
Accuracy of the internal multiple prediction when a time-saving method based ...
 
Ch06 ssm
Ch06 ssmCh06 ssm
Ch06 ssm
 
Ch07 ssm
Ch07 ssmCh07 ssm
Ch07 ssm
 
Gravitational Fields
Gravitational FieldsGravitational Fields
Gravitational Fields
 
Ch04 ssm
Ch04 ssmCh04 ssm
Ch04 ssm
 
Chap9
Chap9Chap9
Chap9
 
Principles of soil dynamics 3rd edition das solutions manual
Principles of soil dynamics 3rd edition das solutions manualPrinciples of soil dynamics 3rd edition das solutions manual
Principles of soil dynamics 3rd edition das solutions manual
 
Coordinate systems
Coordinate systemsCoordinate systems
Coordinate systems
 
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]
Sensor Fusion Study - Ch9. Optimal Smoothing [Hayden]
 
Ch09 ssm
Ch09 ssmCh09 ssm
Ch09 ssm
 
JC A Level H2 Physics Dynamics Notes
JC A Level H2 Physics Dynamics NotesJC A Level H2 Physics Dynamics Notes
JC A Level H2 Physics Dynamics Notes
 
Work and Energy
Work and EnergyWork and Energy
Work and Energy
 
kuramoto
kuramotokuramoto
kuramoto
 
1.1.1 gravitational fields
1.1.1   gravitational fields1.1.1   gravitational fields
1.1.1 gravitational fields
 
Earth 0205-response spectrum
Earth 0205-response spectrumEarth 0205-response spectrum
Earth 0205-response spectrum
 
Work ,energy and power
Work ,energy and powerWork ,energy and power
Work ,energy and power
 
Work energy theorem summary 7 may 2015
Work energy theorem summary 7 may 2015Work energy theorem summary 7 may 2015
Work energy theorem summary 7 may 2015
 

Similar to Computational Physics - modelling the two-dimensional gravitational problem by C++.

dynamics chapt 1 .pptx
dynamics chapt 1 .pptxdynamics chapt 1 .pptx
dynamics chapt 1 .pptxJibrilJundi
 
Study Unit Ill Engineerin M Part4 an1cs By And.docx
Study Unit Ill Engineerin M Part4 an1cs By And.docxStudy Unit Ill Engineerin M Part4 an1cs By And.docx
Study Unit Ill Engineerin M Part4 an1cs By And.docxhanneloremccaffery
 
CollidingParticles.pdf
CollidingParticles.pdfCollidingParticles.pdf
CollidingParticles.pdfDevidasKhatri
 
Physics formulas list
Physics formulas listPhysics formulas list
Physics formulas listhannagrauser1
 
Modelling and Simulations
Modelling and SimulationsModelling and Simulations
Modelling and SimulationsMinjie Lu
 
A Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmA Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmPioneer Natural Resources
 
dynamics chapter 2.pptx
dynamics chapter 2.pptxdynamics chapter 2.pptx
dynamics chapter 2.pptxJibrilJundi
 
Kane’s Method for Robotic Arm Dynamics: a Novel Approach
Kane’s Method for Robotic Arm Dynamics: a Novel ApproachKane’s Method for Robotic Arm Dynamics: a Novel Approach
Kane’s Method for Robotic Arm Dynamics: a Novel ApproachIOSR Journals
 
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...IJRES Journal
 
1_PHYSICAL Quantities to define the laws of physics
1_PHYSICAL Quantities to define the laws of physics1_PHYSICAL Quantities to define the laws of physics
1_PHYSICAL Quantities to define the laws of physicsdhruvpalan123
 
The Equation Based on the Rotational and Orbital Motion of the Planets
The Equation Based on the Rotational and Orbital Motion of the PlanetsThe Equation Based on the Rotational and Orbital Motion of the Planets
The Equation Based on the Rotational and Orbital Motion of the PlanetsIJERA Editor
 
Engineering mechanics system of coplanar forces by
Engineering mechanics system of coplanar forces by Engineering mechanics system of coplanar forces by
Engineering mechanics system of coplanar forces by mashnil Gaddapawar
 

Similar to Computational Physics - modelling the two-dimensional gravitational problem by C++. (20)

PART I.2 - Physical Mathematics
PART I.2 - Physical MathematicsPART I.2 - Physical Mathematics
PART I.2 - Physical Mathematics
 
dynamics chapt 1 .pptx
dynamics chapt 1 .pptxdynamics chapt 1 .pptx
dynamics chapt 1 .pptx
 
Study Unit Ill Engineerin M Part4 an1cs By And.docx
Study Unit Ill Engineerin M Part4 an1cs By And.docxStudy Unit Ill Engineerin M Part4 an1cs By And.docx
Study Unit Ill Engineerin M Part4 an1cs By And.docx
 
CollidingParticles.pdf
CollidingParticles.pdfCollidingParticles.pdf
CollidingParticles.pdf
 
Physics formulas list
Physics formulas listPhysics formulas list
Physics formulas list
 
Modelling and Simulations
Modelling and SimulationsModelling and Simulations
Modelling and Simulations
 
Kinetics of particle
Kinetics of particleKinetics of particle
Kinetics of particle
 
A Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity AlgorithmA Rapid Location Independent Full Tensor Gravity Algorithm
A Rapid Location Independent Full Tensor Gravity Algorithm
 
dynamics chapter 2.pptx
dynamics chapter 2.pptxdynamics chapter 2.pptx
dynamics chapter 2.pptx
 
Quantum Assignment Help
Quantum Assignment HelpQuantum Assignment Help
Quantum Assignment Help
 
Quantum state
Quantum stateQuantum state
Quantum state
 
Kane’s Method for Robotic Arm Dynamics: a Novel Approach
Kane’s Method for Robotic Arm Dynamics: a Novel ApproachKane’s Method for Robotic Arm Dynamics: a Novel Approach
Kane’s Method for Robotic Arm Dynamics: a Novel Approach
 
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...
A Numerical Integration Scheme For The Dynamic Motion Of Rigid Bodies Using T...
 
Ap review total
Ap review totalAp review total
Ap review total
 
Dynamics
DynamicsDynamics
Dynamics
 
08 gravitation
08   gravitation08   gravitation
08 gravitation
 
MD_course.ppt
MD_course.pptMD_course.ppt
MD_course.ppt
 
1_PHYSICAL Quantities to define the laws of physics
1_PHYSICAL Quantities to define the laws of physics1_PHYSICAL Quantities to define the laws of physics
1_PHYSICAL Quantities to define the laws of physics
 
The Equation Based on the Rotational and Orbital Motion of the Planets
The Equation Based on the Rotational and Orbital Motion of the PlanetsThe Equation Based on the Rotational and Orbital Motion of the Planets
The Equation Based on the Rotational and Orbital Motion of the Planets
 
Engineering mechanics system of coplanar forces by
Engineering mechanics system of coplanar forces by Engineering mechanics system of coplanar forces by
Engineering mechanics system of coplanar forces by
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Computational Physics - modelling the two-dimensional gravitational problem by C++.

  • 1. Sultan LeMarc Computational Physics 30/03/2012 The Two Dimensional Gravitational Problem Objective The aim of this project is to model the two-dimensional gravitational problem by a program using the C++ language. The objective of this program is to read, in two dimensions, the initial positions, velocities and masses of two bodies and use Newton’s law of universal gravitation to calculate the two-dimensional forces on each body. It follows this by using Newton’s second law to calculate the acceleration of the bodies in a given time frame in order to establish their movements of the bodies. A file is generated by the program with the positions of both bodies at each time step over a whole time period, which is then used to plot the paths of the two bodies. The two-body gravitational problem concerns the motion of two point masses that interact only with each other due to gravity. Such models are approximated commonly in the Universe, for example the Earth’s orbit around the Sun, the moon’s orbit around the Earth, and two starts orbiting each other. Newton’s Law of Universal Gravitation: Newton published his work on the law of gravity in 1967, introducing the law of universal gravitation, which states that every particle in the Universe attracts every other particle with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them (Serway, 2010). For two bodies, of masses m1 and m2(kg), separated by a distance r (m), the magnitude of the gravitational force, in Newtons (N), is: where G is a constant called the universal gravitational constant. In SI units, it’s value is: This is often referred to as the inverse-square law, as the force varies as the inverse square of the separation of the bodies. As the constant G is used throughout the program, it is declared as a fixed variable by const double G=6.67300E-11. The program makes use of 1D arrays of size [2] for the two-dimensional components of positionpos_m[2], velocity vel_m[2], acceleration acc_m[2],
  • 2. and force gforce_m[2]. Each mass is allocated an array for each of these variables. In order to find the distance that separates the two bodies, r, from the initial x and y positions, the change in each component is used in: This is coded as: dx = pos_m2[0]-pos_m1[0] dy = pos_m2[1]-pos_m1[1] r = sqrt ((dx*dx)+(dy*dy)) This allows the gravitational force acting on each body by the other along the line of action to be found. The two dimensional components of this force is found using trigonometric principles. First, the program finds the angle between the line of action and the x-axis by: This is coded as angle=atan2(dy,dx); This angle is then used to resolve the components of the calculated force: Newton’s third law, which states that if two bodies interact, the force F12 exerted by body 1 on body 2 is equal in magnitude and opposite in direction to the force F21 exerted by body 2 on body 1: Therefore the program implements this by equating the component forces of body 2 as the negative equivalents of the component forces of body 1: gforce_m1[0] = F*cos(angle); gforce_m1[1] = F*sin(angle); gforce_m2[0] = -F*cos(angle); gforce_m2[1] = -F*sin(angle); The two dimensional acceleration is found from these forces by using Newton’s second law, which states that the acceleration of an object is directly proportional to the net force acting on it and inversely proportional to its mass (Serway, 2010):
  • 3. This is applied for each component of the forces for both bodies by: ax1 = Fx1/m1:acc_m1[0] = gforce_m1[0]/m1; ay1 = Fy1/m1:acc_m1[1] = gforce_m1[1]/m1 ax2= Fx2/m2: acc_m2[0] = gforce_m2[0]/m2; ay2 = Fy2/m2: acc_m2[1] = gforce_m2[1]/m2; The acceleration is used to find the change in velocity of each body in a given time step, but first the time step ∆t is determined from the calculated period T. The program assumes that the motion is an orbit. The period of the orbit is determined by the consideration of orbital energy conservation, which requires that the sum of kinetic and potential energies be constant at all points in the motion. The equation for orbital energy conservation, also known as “Vis-Viva” is: wherevr is the relative velocity given by: This is coded as:dv[0] = vel_m2[0]-vel_m1[0]; dv[1] = vel_m2[1]-vel_m1[1]; rel_vel = sqrt((dv[0]*dv[0])+(dv[1]*dv[1])); The program uses this value to find orbital energy by: orb_energy = (0.5*rel_vel*rel_vel)-(G*(m1+m2)/r); This orbital energy acts as the condition which defines the type of orbit experienced by the bodies:  ϵ < 0: Elliptical orbit
  • 4. This corresponds to the minimum and maximum values of r for an elliptical orbit where the distances of closest and farthest approach are equal to r0/1-ε.  ϵ = 0: Parabolic orbit This corresponds to the escape velocity condition as a body is outside the bounds of another body’s gravitational force when energy is equivalent to zero i.e. .  ϵ > 0: Hyperbolic orbit (MIT.edu) In a parabolic or hyperbolic trajectory the motion is not periodic, and the duration of the full trajectory is infinite. Therefore the programprints an error message and aborts program upon the result of a parabolic or hyperbolic orbit when testing for the orbital energy conditions. The semi-major axis is half of the major axis of an ellipse which has a length from the centre to the edge of the ellipse along its principle axes. The orbital energy is used to find the semi-major axis, a, of the elliptical orbit: This is coded by sm_axis = -(G*(m1+m2))/(2*orb_energy). With the semi-major axis value, the period T of the orbit is determined through Kepler’s third law, which states that the square of the orbital period of a planet is directly proportional to the cube of the semi-major axis of its orbit: For this the value of π is declared as a fixed variable to 8 significant figures: const double pi = 3.1415926; The calculation for T is coded as: T = sqrt(fabs((4*pi*pi*sm_axis*sm_axis*sm_axis)/(G*(m1+m2)))); The program determines the time step ∆t according to this calculated period by setting . Having established the time step, the new velocities are found by accumulating the change in velocity, as related by acceleration and the time: .
  • 5. As with acceleration, this is done for each of the components of velocity for both bodies: vel_m1[0] += acc_m1[0]*dt; vel_m1[1] += acc_m1[1]*dt; vel_m2[0] += acc_m2[0]*dt; vel_m2[1] += acc_m2[1]*dt; Finally, the new positions of the bodies are calculated using the following equation of motion: where s is the displacement and u is the initial velocity. As the calculation takes within a for loop where the new velocity after each time step becomes the initial velocity for the next and likewise with position, it is coded as: pos_m1[0] += ((vel_m1[0]*dt)+(0.5*acc_m1[0]*dt*dt)); pos_m1[1] += ((vel_m1[1]*dt)+(0.5*acc_m1[1]*dt*dt)); pos_m2[0] += ((vel_m2[0]*dt)+(0.5*acc_m2[0]*dt*dt)); pos_m2[1] += ((vel_m2[1]*dt)+(0.5*acc_m2[1]*dt*dt)); The program prints the positions of both bodies into a 2D array, position, of size[1001][4] and writes a spread sheet file for excel which can then be plotted. Assumptions  The bodies are point particles; their sizes are negligible centre-to-centre distance is not considered.  If orbital energy is less than zero then orbiting body has two turning points, rmin and rmax. Body gets no closer than rminto central body and no further than rmax due to conservation of angular momentum.  The gravitational fields of the bodies are uniform.  The motion of the bodies as a result of the interaction is closed and periodic i.e. elliptical or circular orbits. Open orbits of parabolic or hyperbolic give void readings.  The two bodies are isolated from the Universe, therefore do not experience gravitational force from any other body i.e. only one central force acting.  Centre of mass of the isolated system is not accelerated.  The larger of the two masses is stationary and fixed at the origin of the system.
  • 6. Figure 1: Plot of X-Y positions of two masses, calculated by program. Program input values: Mass 1: 2E30 Initial Position: 0, 0 Initial Velocity: 0, 0 Mass 2: 6E24 Initial Position: 1.496E11, 0 Initial Velocity: 0, 29E3