Created
May 13, 2017 06:00
-
-
Save idontgetoutmuch/aea2d9c9b3d659c204636d693b2f837e to your computer and use it in GitHub Desktop.
A Rookie Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using StaticArrays | |
| e = 0.6 | |
| q10 = 1 - e | |
| q20 = 0.0 | |
| p10 = 0.0 | |
| p20 = sqrt((1 + e) / (1 - e)) | |
| h = 0.01 | |
| x1 = SVector{2,Float64}(q10, q20) | |
| x2 = SVector{2,Float64}(p10, p20) | |
| x3 = SVector{2,SVector{2,Float64}}(x1,x2) | |
| @inline function oneStep2(h, prev) | |
| h2 = h / 2 | |
| qsPrev = prev[1] | |
| psPrev = prev[2] | |
| function nablaQ(qs) | |
| q1 = qs[1] | |
| q2 = qs[2] | |
| r = (q1^2 + q2^2) ^ (3/2) | |
| return SVector{2,Float64}(q1 / r, q2 / r) | |
| end | |
| function nablaP(ps) | |
| return ps | |
| end | |
| p2 = psPrev - h2 * nablaQ(qsPrev) | |
| qNew = qsPrev + h * nablaP(p2) | |
| pNew = p2 - h2 * nablaQ(qNew) | |
| return SVector{2,SVector{2,Float64}}(qNew, pNew) | |
| end | |
| function manyStepsFinal(n,h,prev) | |
| for i in 1:n | |
| prev = oneStep2(h,prev) | |
| end | |
| return prev | |
| end | |
| final = manyStepsFinal(80000000,h,x3) | |
| print(final) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment