Class: AppMath::Kep2D
- Inherits:
-
Object
- Object
- AppMath::Kep2D
- Defined in:
- lib/kepler_2d.rb
Overview
Kepler problem in 2 dimensions mass of the test particle is 1. space-fixed central mass times constant of gravity is @g
Instance Method Summary collapse
-
#acc ⇒ Object
acceleration.
-
#ang_mom ⇒ Object
angular momentum.
-
#energy ⇒ Object
total energy.
- #get_t ⇒ Object
- #get_x ⇒ Object
- #get_y ⇒ Object
-
#initialize(x, v, g) ⇒ Kep2D
constructor
A new instance of Kep2D.
-
#lenz ⇒ Object
Runge-Lenz vector.
-
#step!(dt) ⇒ Object
time step of the direct midpoint integrator, highly symmetric !.
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#acc ⇒ Object
acceleration
110 111 112 113 114 |
# File 'lib/kepler_2d.rb', line 110 def acc r = @x.abs k = -@g * r**-3 @x * k end |
#ang_mom ⇒ Object
angular momentum
150 151 152 |
# File 'lib/kepler_2d.rb', line 150 def ang_mom @x.x * @v.y - @x.y * @v.x end |
#energy ⇒ Object
total energy
145 146 147 |
# File 'lib/kepler_2d.rb', line 145 def energy @v.abs2 * 0.5 - @g/@x.abs end |
#get_t ⇒ Object
140 141 142 |
# File 'lib/kepler_2d.rb', line 140 def get_t @t end |
#get_x ⇒ Object
132 133 134 |
# File 'lib/kepler_2d.rb', line 132 def get_x @x.x end |
#get_y ⇒ Object
136 137 138 |
# File 'lib/kepler_2d.rb', line 136 def get_y @x.y end |
#lenz ⇒ Object
Runge-Lenz vector
155 156 157 |
# File 'lib/kepler_2d.rb', line 155 def lenz @x * @v.abs2 - @x * @v.spr(@x) - @x.uv * @g end |
#step!(dt) ⇒ Object
time step of the direct midpoint integrator, highly symmetric !
117 118 119 120 121 122 123 124 |
# File 'lib/kepler_2d.rb', line 117 def step!(dt) h = dt * 0.5 @t += h @x += @v * h @v += acc * dt @x += @v * h @t += h end |
#to_s ⇒ Object
126 127 128 129 130 |
# File 'lib/kepler_2d.rb', line 126 def to_s res = "x = " + @x.to_s + "\n" + "v = " + @v.to_s + "\n" + "t = " + @t.to_s end |