Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write C Code Transcribes Newton S Second Law Equations Without Numerical Optimization Name Q35543090

Write a C++ CODE that transcribes Newton’s second law into theequations without any numerical optimization (namely the EULERMETHOD).

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

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

The essential simplication is that the time is discretized intosmall increments (‘time steps’). Suppose that all time steps areequal.

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 theplanet is ~Fi = -(GMm/ri^2 )*^ri, where ^ri is the unit vector inthe radial direction. The acceleration is ~ai = ~Fi/m = -(GM/ri^2)*^ri. We assume that the time step t is so small that during thattime any changes in force and acceleration are negligible, so wecan apply the equations of motion with constant acceleration. Thenwe can easily find that at the end of step i, which is thebeginning of time step (i + 1), the velocity and position are:

~ri+1 = ~ri +~vit +(1/2)~ai*Deltat^2

~vi+1 = ~vi +~ai*Deltat

For the practical implementation we must work with x and ycomponents of the above equations. Angle (theta i) is measured fromthe 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 +~viDeltat+(1/2)~aiDeltat^2 ,

xi+1 = xi + vx;iDeltat +(1/2)ax;iDeltat^2

yi+1 = yi + vy;iDeltat +(1/2)ay;iDeltat^2

~vi+1 = ~vi +~aiDeltat ,

vx;i+1 = vx;i + ax;iDeltat

vy;i+1 = vy;i + ay;iDeltat

The best way to test the model is to initially set the Earth sayalong the x-axis at the initial distance of 1 AU, and the initialvelocity along the y-axis set to be equal to the orbital speed ofthe Earth (which we found to be 29.8 km/s). For the initialconditions (‘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 getthe circular orbit, try increasing the initial speed to Vo = 35km/s. In this case you should get an elliptic orbit.

Leave a Reply

Your email address will not be published. Required fields are marked *