Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong eph for small mu (<100) #167

Open
gomezzz opened this issue Jul 18, 2023 · 0 comments
Open

Wrong eph for small mu (<100) #167

gomezzz opened this issue Jul 18, 2023 · 0 comments
Labels

Comments

@gomezzz
Copy link
Contributor

gomezzz commented Jul 18, 2023

It seems, for small mu values (< 100) , errors for the eph are extremely high / computations become numerically unstable?

The following snippet:

import pykep as pk
import numpy as np 

# Pick some test epoch, problem persists for any
test_epoch = pk.epoch(0)

# Define central body elements, problem persists for any
elements = (1,0,0,0,0,0)

# Some r,v, for orbiting Sat
r = [1000,0.1,0.1]
v = [0.1,0.1,0.1]

# Define central body mu, problems exists only for small MU
for test_planet_mu in np.logspace(-5, 5, 11):
    # Define planet
    test_planet = pk.planet.keplerian(test_epoch,elements,pk.MU_SUN,test_planet_mu,1,1,"test")

    # Define orbiting satellite
    test_satellite = pk.planet.keplerian(test_epoch,r,v,test_planet.mu_self,0,1,1,"test_sat")
    
    r_test,v_test = test_satellite.eph(test_epoch)

    # Compute the difference between the two
    r_diff = np.linalg.norm(np.array(r_test) - np.array(r))
    v_diff = np.linalg.norm(np.array(v_test) - np.array(v))
    print(f"For mu = {test_planet_mu:<10} the difference in r and v is {r_diff:<10.4e} and {v_diff:<10.4e}")

produces

For mu = 1e-05      the difference in r and v is 1.8149e+03 and 1.0162e-07
For mu = 0.0001     the difference in r and v is 8.0696e+03 and 5.9027e-07
For mu = 0.001      the difference in r and v is 3.9075e+01 and 2.3072e-07
For mu = 0.01       the difference in r and v is 1.1187e+03 and 3.5445e-05
For mu = 0.1        the difference in r and v is 8.5343e+01 and 1.4133e-03
For mu = 1.0        the difference in r and v is 2.3625e+03 and 9.1964e-03
For mu = 10.0       the difference in r and v is 6.3135e+03 and 6.9916e-02
For mu = 100.0      the difference in r and v is 1.5194e-12 and 5.9691e-16
For mu = 1000.0     the difference in r and v is 1.2010e-11 and 6.8129e-14
For mu = 10000.0    the difference in r and v is 2.4689e-11 and 1.6205e-12
For mu = 100000.0   the difference in r and v is 1.0816e-09 and 7.2581e-10

@darioizzo maybe this is expected as numerical instability? But then a warning when creating keplerian planets with small MU would be really nice, I think?

(This is pykep 2.6 from conda on windows fwiw)

@gomezzz gomezzz added the bug label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant