[Closed] Same calculation different results
I need a sanity check! This is a code fragment that’s part of a position script controller. It’s been giving me nightmares. To troubleshoot, I’ve temporarily put in two print statements to check my calculations. They should print the same results, but they don’t! The first is giving me a very small value (0.99969d0). The second gives me a very large value (1.43784d+008). I’m sure I’m doing something stupid in my code, but I’m stuck. :banghead: What am I doing wrong?
The first print takes the form of Print (calculation)
The second is variable=(same calculation)
print variable
Print statements are near the bottom.
Thanks in advance!
fn getTrueAnomaly satellite inMeanAnomaly = (
result = #(0.0d-0,0.0d-0,0.0d-0)
local kAccuracyToComputeE0To = 2d-13
local kFarTooManyLoops = 100
local dE = 0d-0
local E0 = inMeanAnomaly
local count =0
do (
dE = ((inMeanAnomaly + satellite.tledata.eccentricity * sin(E0) - E0) / (1.0 - satellite.tledata.eccentricity * cos(E0)))
E0 = E0 + dE
count +=1
)
while ((abs(dE) > kAccuracyToComputeE0To) and count < kFarTooManyLoops)
local cosOfE0 = cos(E0)
local theX = (cosOfE0 - satellite.tledata.eccentricity)
local theY = sqrt((1.0 - satellite.tledata.eccentricity) * (1.0 + satellite.tledata.eccentricity)) * sin(E0)
result[1] = 0.0
result[2] = mod2pi(atan2 theY theX)
result[3] = (1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double)
print (1.0 - satellite.tledata.eccentricity * cosOfE0) * (satellite.tledata.semiMajorAxis as double)
print result[3]
result
)
Thanks DenisT. I knew I was doing something stupid. Now that my checks are behaving as expected, I can get on with figuring out why it isn’t working as expected overall.