// Kepler2 solves Kepler's equation by iteration. // // The iterated formula is // // E1 = E0 + (M + e * sin(E0) - E0) / (1 - e * cos(E0)) // // Argument e is eccentricity, M is mean anomoly in radians, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly in radians. // // The function converges over a wider range of inputs than does Kepler1 // but it also fails to converge for some values of e and M. func Kepler2(e, M float64, places int) (E float64, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) return E0 + (M+e*se-E0)/(1-e*ce) // (30.7) p. 199 } return iterate.DecimalPlaces(f, M, places, places) }
// Kepler1 solves Kepler's equation by iteration. // // The iterated formula is // // E1 = M + e * sin(E0) // // Argument e is eccentricity, M is mean anomaly, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly. // // For some vaues of e and M it will fail to converge and the // function will return an error. func Kepler1(e float64, M unit.Angle, places int) (E unit.Angle, err error) { f := func(E0 float64) float64 { return M.Rad() + e*math.Sin(E0) // (30.5) p. 195 } ea, err := iterate.DecimalPlaces(f, M.Rad(), places, places*5) return unit.Angle(ea), err }
// Kepler2 solves Kepler's equation by iteration. // // The iterated formula is // // E1 = E0 + (M + e * sin(E0) - E0) / (1 - e * cos(E0)) // // Argument e is eccentricity, M is mean anomaly, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly. // // The function converges over a wider range of inputs than does Kepler1 // but it also fails to converge for some values of e and M. func Kepler2(e float64, M unit.Angle, places int) (E unit.Angle, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) return E0 + (M.Rad()+e*se-E0)/(1-e*ce) // (30.7) p. 199 } ea, err := iterate.DecimalPlaces(f, M.Rad(), places, places) return unit.Angle(ea), err }
// Kepler2a solves Kepler's equation by iteration. // // The iterated formula is the same as in Kepler2 but a limiting function // avoids divergence. // // Argument e is eccentricity, M is mean anomoly in radians, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly in radians. func Kepler2a(e, M float64, places int) (E float64, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) // method of Leingärtner, p. 205 return E0 + math.Asin(math.Sin((M+e*se-E0)/(1-e*ce))) } return iterate.DecimalPlaces(f, M, places, places*5) }
// Kepler2a solves Kepler's equation by iteration. // // The iterated formula is the same as in Kepler2 but a limiting function // avoids divergence. // // Argument e is eccentricity, M is mean anomaly, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly. func Kepler2a(e float64, M unit.Angle, places int) (E unit.Angle, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) // method of Leingärtner, p. 205 return E0 + math.Asin(math.Sin((M.Rad()+e*se-E0)/(1-e*ce))) } ea, err := iterate.DecimalPlaces(f, M.Rad(), places, places*5) return unit.Angle(ea), err }
// Kepler2b solves Kepler's equation by iteration. // // The iterated formula is the same as in Kepler2 but a (different) limiting // function avoids divergence. // // Argument e is eccentricity, M is mean anomoly in radians, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly in radians. func Kepler2b(e, M float64, places int) (E float64, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) d := (M + e*se - E0) / (1 - e*ce) // method of Steele, p. 205 if d > .5 { d = .5 } else if d < -.5 { d = -.5 } return E0 + d } return iterate.DecimalPlaces(f, M, places, places) }
// Kepler2b solves Kepler's equation by iteration. // // The iterated formula is the same as in Kepler2 but a (different) limiting // function avoids divergence. // // Argument e is eccentricity, M is mean anomaly, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly. func Kepler2b(e float64, M unit.Angle, places int) (E unit.Angle, err error) { f := func(E0 float64) float64 { se, ce := math.Sincos(E0) d := (M.Rad() + e*se - E0) / (1 - e*ce) // method of Steele, p. 205 if d > .5 { d = .5 } else if d < -.5 { d = -.5 } return E0 + d } ea, err := iterate.DecimalPlaces(f, M.Rad(), places, places) return unit.Angle(ea), err }
func ExampleDecimalPlaces() { // Example 5.a, p. 48. betterSqrt := func(N float64) iterate.BetterFunc { return func(n float64) float64 { return (n + N/n) / 2 } } start := 12. places := 8 maxIter := 20 n, err := iterate.DecimalPlaces(betterSqrt(159), start, places, maxIter) if err != nil { fmt.Println(err) return } fmt.Printf("%.*f", places, n) // Output: // 12.60952021 }
// Kepler1 solves Kepler's equation by iteration. // // The iterated formula is // // E1 = M + e * sin(E0) // // Argument e is eccentricity, M is mean anomoly in radians, // places is the desired number of decimal places in the result. // // Result E is eccentric anomaly in radians. // // For some vaues of e and M it will fail to converge and the // function will return an error. func Kepler1(e, M float64, places int) (E float64, err error) { f := func(E0 float64) float64 { return M + e*math.Sin(E0) // (30.5) p. 195 } return iterate.DecimalPlaces(f, M, places, places*5) }