# Julia now has a native SGP4/SDP4 implementation

**URL:** <https://discourse.julialang.org/t/julia-now-has-a-native-sgp4-sdp4-implementation/11376>\
**Category:** Astro/Space\
**Created:** [June 2, 2018, 9:13pm UTC](https://discourse.julialang.org/t/julia-now-has-a-native-sgp4-sdp4-implementation/11376 "2018-06-02T21:13:23Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [June 4, 2018, 9:25pm UTC](https://discourse.julialang.org/t/julia-now-has-a-native-sgp4-sdp4-implementation/11376/21 "2018-06-04T21:25:00Z")

</div>

@crbinz

I compare the results using Vallado’s implementation in Matlab and SatelliteToolbox.jl for the very same orbit you have considered:

# Matlab

```julia-auto
>> l1 = '1 23599U 95029B 06171.76535463 .00085586 12891-6 12956-2 0 2905';
>> l2 = '2 23599 6.9327 0.2849 5782022 274.4436 25.2425 4.47796565123555';
>> [~, ~, ~, satrec] = twoline2rv(l1,l2,'c','m','a',84);
>> [satrec, r, v] = sgp4(satrec, 5*24*60);
>> r

r =

   1.0e+04 *

  -0.314979672773600 2.410064502724234 0.289071440453531

>> v

v =

  -2.619571867673193 -0.196802903816630 -0.049489996758654

```

# Julia

```julia
julia> tle = read_tle_from_string("1 23599U 95029B 06171.76535463 .00085586 12891-6 12956-2 0 2905",
                                  "2 23599 6.9327 0.2849 5782022 274.4436 25.2425 4.47796565123555");

julia> orbp = init_orbit_propagator(Val{:sgp4}, tle[1]);

julia> r,v = sgp4!(orbp.sgp4d, 5*24*60);

julia> println(r[1], " ", r[2], " ", r[3])
-3149.796727736229 24100.64502724232 2890.7144045353007

julia> println(v[1], " ", v[2], " ", v[3])
-2.6195718676731854 -0.19680290381668744 -0.04948999675866066

```

I think we are equal to Matlab code up to machine precision.

---

<div class="post-metadata">

**Author:** ![crbinz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crbinz/32/1919_2.png) [@crbinz](https://discourse.julialang.org/u/crbinz)\
**Post date:** [June 4, 2018, 10:47pm UTC](https://discourse.julialang.org/t/julia-now-has-a-native-sgp4-sdp4-implementation/11376/22 "2018-06-04T22:47:33Z")

</div>

You’re right - [the python library does not use AFSPC mode by default](https://github.com/brandon-rhodes/python-sgp4/blob/master/sgp4/io.py#L102), although I also found a different bug in the wrapper code.

Here are the results using AFSPC mode:

```julia
julia> r,v = SGP4.sgp4(satellite, 5*24*60)
([-3149.8, 24100.6, 2890.71], [-2.61957, -0.196803, -0.04949])

julia> println(r[1]," ", r[2], " ", r[3], " ")
-3149.7967277359576 24100.645027242346 2890.714404535306

julia> println(v[1]," ", v[2], " ", v[3], " ")
-2.6195718676731934 -0.19680290381662707 -0.04948999675865344

```

I also edited my post with the benchmarks to use a different method with less overhead – still much slower.

[Previous page](https://discourse.julialang.org/t/julia-now-has-a-native-sgp4-sdp4-implementation/11376.md?page=1)
