<p>The difference in values seems to be only <span class="math-container">$2\pi$</span>, or one complete turn. So your value seems to be correct.</p>
<p>Here is my calculation:</p>
<p>Jupiter was at perihelion on March 17th 2011, which is 2672 days after your date. Jupiter has a  period of 4330 days, so I calculate the mean anomaly to be <span class="math-container">$$(4330-2672)/4330 × 2\pi=2.4059$$</span></p>
<p>But it seems you are calculating the Mean Anomaly from the 1987 perihelion, so add <span class="math-container">$2\pi$</span> to give <span class="math-container">$M=8.689$</span>  (that is very close to your value and the differences are probably because you've been more careful than me in rounding etc)</p>
<p>While I feel you <em>should</em> reduce this to the range 0-2pi, you should be able to solve Kepler's equation with this value, and your solution is correct (I checked by graphing M = E-e sin(E) online with GeoGebra).  As expected with a nearly circular orbit (e=0.0489), <span class="math-container">$M\approx E=8.72$</span>  I'd still reduce this to the range 0-2pi, to get the book value of E=2.43.</p>

CC BY-SA 4.0
2021-12-31T13:49:20.710Z
Thanks for your answer. My answer for all of your question is **yes**. I have updated my question with more details.
VansFannel
CC BY-SA 4.0
2021-12-31T14:04:48.680Z
If I reduce the value of 8.6884193953285500 to 2.4052341153285512 (I subtract it 2pi), I get the same value than in the book.
VansFannel
CC BY-SA 4.0
2021-12-31T14:28:36.180Z
Then what is 5.527600?
James K
CC BY-SA 4.0
2021-12-31T15:49:59.390Z
My mistake.....
VansFannel
CC BY-SA 4.0
2022-01-04T09:37:10.180Z
Again, thanks a lot for your help. I have a question: do you know if there is a book to learn about all of this (mean anomaly, true anomaly, orbits, eccentricity...) because I'm implementing a library without knowing about what I am doing.
VansFannel
CC BY-SA 4.0
2022-01-04T18:14:14.780Z
Meeus *Astronomical Algorithms* is probably the best known reference, but getting hold of a copy now may be difficult.  https://www.worldcat.org/title/astronomical-algorithms/oclc/1110649364
James K
CC BY-SA 4.0
2021-12-31T12:27:28.383Z
2021-12-31T15:55:09.250Z
2021-12-31T15:55:09.250Z
James K
<p>I'm developing a C++ computer library with the formulas in the book &quot;<a href="https://rads.stackoverflow.com/amzn/click/com/B00E3UR5FQ" rel="nofollow noreferrer">Practical Astronomy with your Calculator or Spreadsheet 4th Edition</a>&quot; but I have a problem with the formula 56, &quot;<strong>Perturbations in a planet's orbit</strong>&quot;.</p>
<p>The book talks about using the <em>Kepler's equation</em> to calculate the <strong>eccentric anomaly</strong>, E. To do it I have implemented this routine:</p>
<pre><code>double TheSun::RoutineR2(double meanAnomaly, double eccentricity)
{
    double E = 0.0;
    double aux = 0.0;
    double delta = 0.0;

    // Epsilon is the required accuracy (= 10^-6 radians).
    double epsilon = 0.000001;

    // 1. First guest, E = E0 = M.
    E = aux = meanAnomaly;
    
    do
    {
        // 2. Find the value of delta = E - esin(E) - M;
        delta = aux - eccentricity * std::sin(aux) - meanAnomaly;

        // 3. If delta gets enough accuracy, end here.
        if (std::abs(delta) &lt;= epsilon)
            break;

        // 4. Find E growth.
        double growth = delta / (1 - eccentricity * std::cos(aux));

        // 5. Take the new value.
        aux = aux - growth;

    } while (true);

    return aux;
}
</code></pre>
<p>When I try to find the <strong>eccentric anomaly</strong>, E, for planet Jupiter on 22 November 2003, I get that <em>E</em> is equal to <code>8.7201007604944394</code> but, in the book, the value for <em>E</em> is 2.436915 radians.</p>
<p>The input value for <code>RoutineR2</code> are:</p>
<pre><code>meanAnomaly = 8.6884193953285500
eccentricity = 0.048906999999999999
</code></pre>
<p><strong>The values above are the same than the book uses</strong>.</p>
<p>I have calculated the <em>mean anomaly</em> and I get the same value than the book. The <em>eccentricity</em> is the eccentricity of the orbit of Jupiter. I take it from the Table 8 in the book. This table has the values of <em>Elements of the planetary orbits at epoch 2010.0</em>.</p>
<p>Is the book wrong? Am I wrong?</p>
<p>Maybe my implementation of Kepler's equation is wrong or I'm not using the right value for eccentricity.</p>

CC BY-SA 4.0
2021-12-31T11:34:17.657Z
The answer for Eccentric Anomaly looks reasonable given the input for Mean Anomaly and the low eccentricity;  Mean anomaly and eccentric anomaly _are_ going to be pretty close in value under those circumstances. How did you get your value for Mean Anomaly on 22 November 2003?
notovny
<kepler><keplers-laws>
Calculate eccentric anomaly using Kepler's equation
VansFannel
# Calculate eccentric anomaly using Kepler's equation

(Asked by: username_0 on 2021-12-31)

I'm developing a C++ computer library with the formulas in the book "[Practical Astronomy with your Calculator or Spreadsheet 4th Edition](https://rads.stackoverflow.com/amzn/click/com/B00E3UR5FQ)" but I have a problem with the formula 56, "**Perturbations in a planet's orbit**".

The book talks about using the *Kepler's equation* to calculate the **eccentric anomaly**, E. To do it I have implemented this routine:

```
double TheSun::RoutineR2(double meanAnomaly, double eccentricity)
{
    double E = 0.0;
    double aux = 0.0;
    double delta = 0.0;

    // Epsilon is the required accuracy (= 10^-6 radians).
    double epsilon = 0.000001;

    // 1. First guest, E = E0 = M.
    E = aux = meanAnomaly;
    
    do
    {
        // 2. Find the value of delta = E - esin(E) - M;
        delta = aux - eccentricity * std::sin(aux) - meanAnomaly;

        // 3. If delta gets enough accuracy, end here.
        if (std::abs(delta) <= epsilon)
            break;

        // 4. Find E growth.
        double growth = delta / (1 - eccentricity * std::cos(aux));

        // 5. Take the new value.
        aux = aux - growth;

    } while (true);

    return aux;
}

```

When I try to find the **eccentric anomaly**, E, for planet Jupiter on 22 November 2003, I get that *E* is equal to `8.7201007604944394` but, in the book, the value for *E* is 2.436915 radians.

The input value for `RoutineR2` are:

```
meanAnomaly = 8.6884193953285500
eccentricity = 0.048906999999999999

```

**The values above are the same than the book uses**.

I have calculated the *mean anomaly* and I get the same value than the book. The *eccentricity* is the eccentricity of the orbit of Jupiter. I take it from the Table 8 in the book. This table has the values of *Elements of the planetary orbits at epoch 2010.0*.

Is the book wrong? Am I wrong?

Maybe my implementation of Kepler's equation is wrong or I'm not using the right value for eccentricity.

**Tags:** kepler, keplers-laws

> **Comments:**
> **username_1**: The answer for Eccentric Anomaly looks reasonable given the input for Mean Anomaly and the low eccentricity;  Mean anomaly and eccentric anomaly _are_ going to be pretty close in value under those circumstances. How did you get your value for Mean Anomaly on 22 November 2003?  

---

## 1 answers

### Answer by username_2 on 2021-12-31. Score: 6 | Accepted answer

The difference in values seems to be only $2\pi$, or one complete turn. So your value seems to be correct.

Here is my calculation:

Jupiter was at perihelion on March 17th 2011, which is 2672 days after your date. Jupiter has a period of 4330 days, so I calculate the mean anomaly to be $$(4330-2672)/4330 × 2\pi=2.4059$$

But it seems you are calculating the Mean Anomaly from the 1987 perihelion, so add $2\pi$ to give $M=8.689$ (that is very close to your value and the differences are probably because you've been more careful than me in rounding etc)

While I feel you *should* reduce this to the range 0-2pi, you should be able to solve Kepler's equation with this value, and your solution is correct (I checked by graphing M = E-e sin(E) online with GeoGebra). As expected with a nearly circular orbit (e=0.0489), $M\approx E=8.72$ I'd still reduce this to the range 0-2pi, to get the book value of E=2.43.

> **Comments:**
> **username_0**: Thanks for your answer. My answer for all of your question is **yes**. I have updated my question with more details.  
> **username_0**: If I reduce the value of 8.6884193953285500 to 2.4052341153285512 (I subtract it 2pi), I get the same value than in the book.  
> **username_2**: Then what is 5.527600?  
> **username_0**: My mistake.....  
> **username_0**: Again, thanks a lot for your help. I have a question: do you know if there is a book to learn about all of this (mean anomaly, true anomaly, orbits, eccentricity...) because I'm implementing a library without knowing about what I am doing.  
> **username_2**: Meeus *Astronomical Algorithms* is probably the best known reference, but getting hold of a copy now may be difficult.  https://www.worldcat.org/title/astronomical-algorithms/oclc/1110649364  

---

