سؤال

I am having problem to get a numerical value for this expression where I am trying to calculate the daylight hours using this formula. Its ending up giving a NaN when I evaluate this expression.

J stand for Julian day. (for e.g today J = 172;)

Any help will be highly valuable, Thanks

P = Math.asin(0.39795*Math.cos(0.2163108 + 2*Math.atan(0.9671396*Math.tan[0.00860*(J-186)])));
هل كانت مفيدة؟

المحلول

I tried it and got an answer ... :

P = Math.Asin(0.39795 * Math.Cos(0.2163108 + 2 * Math.Atan(0.9671396 * Math.Tan(0.00860 * (J- 186)))));

I changed the "[" to "(" in Math.tan[0.00860*(J-186)])))

And I got a result ... (To test it I changed J to 172)

Make sure the P is a Double

نصائح أخرى

    //GET LATITUDE
            latitude = document.getElementById("latit").value;
            L = latitude;

            //GET JULIAN DAY
              Now=new Date();
              Now_Y=Now.getYear();
              if (Now_Y < 70)   { Now_Y=Now_Y*1+2000; }
              if (Now_Y < 1900) { Now_Y=Now_Y*1+1900; }
              Now_M=Now.getMonth();                     // Jan-Dec = 0-11
              Now_D=Now.getDate();                      // 1-31
              Now_H=Now.getHours();                     // 0-23
              Now_N=Now.getMinutes();                   // 0-59
              Now_S=Now.getSeconds();                   // 0-59
              Now_U=Now.getMilliseconds();              // 0-999
              Now_T=Now.getTime();                      // miliseconds since 1970-01-01
              Now_O=Now.getTimezoneOffset();            // in minutes
              Now_W=Now.getDay();                       // weekday: Sun-Sat = 0-6
              Now_J=                                    // day of year (Julian day)
                Math.round((                            // ...account for DST
                (new Date(Now_Y,Now_M,Now_D))           // ...most recent midnight
                - (new Date(Now_Y,0,0)))                // ...Dec. 31st midnight
                /86400000);                             // ...mili-seconds per day
              Gmt_N=Now_N+Now_O;
              Gmt=new Date(Now_Y,Now_M,Now_D,Now_H,Gmt_N,Now_S);
              Gmt_Y=Gmt.getYear();
              if (Gmt_Y < 70)   { Gmt_Y=Gmt_Y*1+2000; }
              if (Gmt_Y < 1900) { Gmt_Y=Gmt_Y*1+1900; }
              Gmt_M=Gmt.getMonth();                     // Jan-Dec = 0-11
              Gmt_D=Gmt.getDate();                      // 1-31
              Gmt_J=                                    // day of year (Julian day)
                Math.round((                            // ...account for DST
                (new Date(Gmt_Y,Gmt_M,Gmt_D))           // ...most recent midnight
                - (new Date(Gmt_Y,0,0)))                // ...Dec. 31st midnight
                /86400000);                             // ...mili-seconds per day
                alert("Julian Day: "+Gmt_J);

            J = Gmt_J;

            P = Math.asin(0.39795*Math.cos(0.2163108 + 2*Math.atan(0.9671396*Math.tan(0.00860*(J-186)))));

            alert("P is : "+P)

            pi = 3.14159265;

            var D = 24 - (24/pi)*Math.acos((Math.sin(0.8333*pi/180) + Math.sin(L*pi/180)*Math.sin(P))/ (Math.cos(L*pi/18

0)*Math.cos(P)));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top