jeudi 25 octobre 2018

loop a math formula until two values are equal

I'm trying to work on a complicated math equation and part of it involves looping values until they are a specific difference apart.

Here is my attempt at this:

 public void EccentricAnomaly (double M){
 double E = M + e 
 if (e > 0.06) {
 E0 = E;
 double anglesInRadianE = Math.toRadians(E0);
 double E1 = E0 -( E0 - e* Math.sin(angleInRadiansE)-M / (1 - e * Math.cos(angleINRadianE));
     if (E1-E0 !=0.001){
           E1 = E0;
           E1 = E0 -( E0 - e* Math.sin(angleInRadiansE)-M / (1 - e * Math.cos(angleINRadianE));
   }
  v = Math.cos(E1) - e;
  x = Math.sqrt(e);

 }else{

 v = Math.cos(E) - e

 }

The issue is that if e from a previous calculation is greater than 0.06, E1 is calculated but if the difference between that and E0 is greater than 0.001 the formula used to calculated E1 is done again, this time E1 becomes E0 and a new E1 is calculated. This should repeat until difference between E1 and E0 is 0.001. As you can see I'm confused how to program this so any help would be appreciated. I think this is the right path but this current code seems to just be repeating the same values.

Aucun commentaire:

Enregistrer un commentaire