예제 #1
0
파일: kepler.go 프로젝트: thecc4re/meeus
// 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)
}
예제 #2
0
파일: kepler.go 프로젝트: soniakeys/meeus
// 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
}
예제 #3
0
파일: kepler.go 프로젝트: soniakeys/meeus
// 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
}
예제 #4
0
파일: kepler.go 프로젝트: thecc4re/meeus
// 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)
}
예제 #5
0
파일: kepler.go 프로젝트: soniakeys/meeus
// 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
}
예제 #6
0
파일: kepler.go 프로젝트: thecc4re/meeus
// 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)
}
예제 #7
0
파일: kepler.go 프로젝트: soniakeys/meeus
// 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
}
예제 #8
0
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
}
예제 #9
0
파일: kepler.go 프로젝트: thecc4re/meeus
// 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)
}