Question: Write a C++ CODE that transcribes Newton's second law into the equations without any numerical optimization (namely the EULER METHOD). We will consider a planet

Write a C++ CODE that transcribes Newton's second law into the equations without any numerical optimization (namely the EULER METHOD).

We will consider a planet of mass m orbiting an unmovable star of mass M (let's say it's the Earth and the Sun). The plane of motion is determined by the position and velocity vectors of the planet:

~r = (x; y) and ~v = (vx; vy), which are given as the initial conditions.

The essential simplication is that the time is discretized into small increments ('time steps'). Suppose that all time steps are equal.

At the beginning of the i-th step the position of the planet is ~ri and its velocity is ~vi. At that time the force acting on the planet is ~Fi = -(GMm/ri^2 )*^ri, where ^ri is the unit vector in the radial direction. The acceleration is ~ai = ~Fi/m = -(GM/ri^2 )*^ri. We assume that the time step t is so small that during that time any changes in force and acceleration are negligible, so we can apply the equations of motion with constant acceleration. Then we can easily find that at the end of step i, which is the beginning of time step (i + 1), the velocity and position are:

~ri+1 = ~ri +~vit +(1/2)~ai*Write a C++ CODE that transcribes Newton's second law into the equationst^2

~vi+1 = ~vi +~ai*without any numerical optimization (namely the EULER METHOD). We will consider at

For the practical implementation we must work with x and y components of the above equations. Angle (theta i) is measured from the x-axis to the position vector in i-th step;

cos(theta i)= xi/ri,

sin(theta i) = yi/ri

ri =sqrt(xi^2 + yi^2)

~ai = -(GM/ri^2)*^ri

ax;i = -(GM/ri^2)cos(theta i) = -GM (xi/ri^3)

ay;i = -(GM/ri^2)sin(theta i) = -GM(yi/ri^3)

~ri+1 = ~ri +~viplanet of mass m orbiting an unmovable star of mass M (let'st +(1/2)~aisay it's the Earth and the Sun). The plane of motion ist^2 ,

xi+1 = xi + vx;idetermined by the position and velocity vectors of the planet: ~r =t + (1/2)ax;i(x; y) and ~v = (vx; vy), which are given as thet^2

yi+1 = yi + vy;iinitial conditions. The essential simplication is that the time is discretized intot + (1/2)ay;ismall increments ('time steps'). Suppose that all time steps are equal. Att^2

~vi+1 = ~vi +~aithe beginning of the i-th step the position of the planet ist ,

vx;i+1 = vx;i + ax;i~ri and its velocity is ~vi. At that time the force actingt

vy;i+1 = vy;i + ay;ion the planet is ~Fi = -(GMm/ri^2 )*^ri, where ^ri is thet

The best way to test the model is to initially set the Earth say along the x-axis at the initial distance of 1 AU, and the initial velocity along the y-axis set to be equal to the orbital speed of the Earth (which we found to be 29.8 km/s). For the initial conditions ('zeroth step') x0 = 1 AU, y0 = 0, vx;0 = 0 and vy;0 = 29.8 km/s we know that the orbit should be circular. Once you get the circular orbit, try increasing the initial speed to Vo = 35 km/s. In this case you should get an elliptic orbit.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!