0

i need to find out moon longitude value for finding Nakshatra and tithi.

i use below c language code for getting moon longitude,

 //Longitude of Moon
    static double moon_long(double d)
    {
    double N, i, w, a, e, M, E, Et, x, y, r, v, xec, yec, zec, D, F, tmp, tmp1, tmp2, lon;

    N = 125.1228-0.0529538083*d;
    i = 5.1454;
    w = REV(318.0634+0.1643573223*d);
    a = 60.2666;
    e = 0.054900;
    M = REV(115.3654+13.0649929509*d);
    Mm = M;
    Lm = N+w+M;

    //Calculate Eccentricity anamoly
    tmp = M*D2R;
    E = M+R2D*e*sin(tmp)*(1+e*cos(tmp));

    tmp = E*D2R;
    Et = E-(E-R2D*e*sin(tmp)-M)/(1-e*cos(tmp));

    do {
        E = Et;
        tmp = E*D2R;
        Et = E-(E-R2D*e*sin(tmp)-M)/(1-e*cos(tmp));
    } while(E-Et>0.005);

    tmp = E*D2R;
    x = a*(cos(tmp)-e);
    y = a*sqrt(1-e*e)*sin(tmp);

    r = sqrt(x*x + y*y);
    v = REV(R2D*atan2(y,x));

    tmp = D2R*N;
    tmp1 = D2R*(v+w);
    tmp2 = D2R*i;
    xec = r*(cos(tmp)*cos(tmp1)-sin(tmp)*sin(tmp1)*cos(tmp2));
    yec = r*(sin(tmp)*cos(tmp1)+cos(tmp)*sin(tmp1)*cos(tmp2));
    zec = r*sin(tmp1)*sin(tmp2);

    //Do some corrections
    D = Lm - Ls;
    F = Lm - N;

    lon = R2D*atan2(yec,xec);

    lon+= -1.274*sin((Mm-2*D)*D2R);
    lon+= +0.658*sin((2*D)*D2R);
    lon+= -0.186*sin((Ms)*D2R);
    lon+= -0.059*sin((2*Mm-2*D)*D2R);
    lon+= -0.057*sin((Mm-2*D+Ms)*D2R);
    lon+= +0.053*sin((Mm+2*D)*D2R);
    lon+= +0.046*sin((2*D-Ms)*D2R);
    lon+= +0.041*sin((Mm-Ms)*D2R);
    lon+= -0.035*sin((D)*D2R);
    lon+= -0.031*sin((Mm+Ms)*D2R);
    lon+= -0.015*sin((2*F-2*D)*D2R);
    lon+= +0.011*sin((Mm-4*D)*D2R);

    return REV(lon);
}

but i got wrong value, could you please explain me, how to moon longitude or which procedure i should use for it.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Ravi
  • 888
  • 6
  • 24
  • 2
    "I got wrong value". How do you know? For a particular set of inputs, do you know what the right answer is? What is the source of your code / equations? What does `REV` do? Is `D2R` pi/180? Might I recommend that you use a naming convention where variables that contain degrees are suffixed `_d`, and radians `_r`; it will help in debugging (although it may not be your problem today). You don't give enough information to allow us to help you... – Floris Sep 26 '13 at 12:37
  • i have JS file, when i run both files, its showing different values, i need to find nakshatra and tithi using date-time. by using JS file i'm getting correct result – Ravi Sep 26 '13 at 12:39
  • May I suggest that you put the other source code (of the JS) in the question as well - then we can help compare. – Floris Sep 26 '13 at 12:41
  • both logics are different that is totally static data – Ravi Sep 26 '13 at 12:42
  • 2
    How do you know it is correct? And what is the source of your equations? There are three possible reasons: 1) your reference is wrong; 2) your equations are wrong; 3) your implementation of the equations is wrong. Unless we see more we can't tell you which it is. I do strongly urge you to look at the D2R and R2D mess you are making; decide to work in all radians, or use `sind` etc and work in all degrees. See http://stackoverflow.com/a/15324737/1967396 for how to implement. – Floris Sep 26 '13 at 12:44
  • we have today data in written format (astology book), i'm using today date only – Ravi Sep 26 '13 at 12:46
  • +1 for question title! funny :) – gaussblurinc Sep 26 '13 at 12:46
  • OK. Let's assume your reference astrology book is correct. Then do you have a source for your equations / algorithm? And **what is `REV`**??? – Floris Sep 26 '13 at 12:48
  • Am I right in thinking that you are using https://github.com/santhoshn/panchanga/blob/master/plib.c as a reference - or another place? It would be helpful to know where you are starting from; and perhaps you could say "for this date, this location, I expect the answer X based on source A, and I am getting the answer Y. What is the difference?" Perhaps it's a matter of coordinate system, etc. Is the error very large or very small? – Floris Sep 26 '13 at 13:00

1 Answers1

0

It is hard to tell you "what is wrong" since you are not answering some of the questions asked in the comments. Using one of the lines of your code, I found an implementation of what I think you are after at https://github.com/santhoshn/panchanga

I built the code (moving everything into its own directory, then compiling with

gcc *.c -lm -o panchanga

And tested it using today's date, and the time zone of Mumbai, India:

panchanga -d 26/09/2013 -t 20:02 -z +5:30

Output:

Tithi     : Saptami, Krishna Paksha
Nakshatra : Mrigashira
Yoga      : Vyatipata
Karana    : Bava
Rashi     : Mithuna

I don't know what these mean, but I confirmed the results against http://www.drikpanchang.com/?l=10455 - and they agreed.

My advice to you: see how this solution differs from what you are doing - that's how you will find "what is wrong with your code".

Floris
  • 45,857
  • 6
  • 70
  • 122