Re: Re: First function debug help
- To: mathgroup at smc.vnet.net
- Subject: [mg106685] Re: [mg106665] Re: [mg106627] First function debug help
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Thu, 21 Jan 2010 04:51:47 -0500 (EST)
- References: <201001191013.FAA29027@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Actually, BOTH functions fail, and for the same reason, nothing to do with h. Since m_ is used twice in each function signature, once for months and again for minutes, the functions only work when months = seconds. A couple of examples: julianDayModified[y_, m_, d_, h_, m_, s_] := (b = 2 - IntegerPart[y/100] + IntegerPart[IntegerPart[y/100]/4]; f = d + (h/24) + (m/(24*60)) + (s/(24*3600)); jd = IntegerPart[(365.25*(y + 4716))] + IntegerPart[(30.6001*(m + 1))] + d + b - 1524.5; mjd = jd - 2400000.5; mjd) julianDayModified[2010, 1, 1, 12, 0, 0] julianDayModified[2010, 1, 1, 12, 0, 0] (no evaluation, because no match) julianDayModified[2010, 1, 1, 12, 1, 0] 55195. Instead, try something like: Clear@julianDayModified julianDayModified[y_, month_, d_, h_, minute_, s_] := (b = 2 - IntegerPart[y/100] + IntegerPart[IntegerPart[y/100]/4]; f = d + (h/24) + (minute/(24*60)) + (s/(24*3600)); jd = IntegerPart[(365.25*(y + 4716))] + IntegerPart[(30.6001*(month + 1))] + d + b - 1524.5; mjd = jd - 2400000.5; mjd) Bobby On Wed, 20 Jan 2010 05:50:48 -0600, Herman Kuun <oomkoos1 at gmail.com> wrote: > The hour input 'h_' is not used in the defined function. > > Substitute > d = d + ((m * 60 )/ ( 24 * 60 )) + ((s * 3600)/(24 * 3600)); > with > f = d + (h/24) + (m/(24*60)) + (s/(24*3600)); > > Also try make it a habit to start your own variable and function > definitions > in lower case. Mathematica uses upper case exclusively. Save you lots of > frustration in the future. > > This will calculate corectly: > ------------------------------------------------------------------------------------------------------------ > > julianDayModified[y_, m_, d_, h_, m_, s_] := ( > > b = 2 - IntegerPart[y/100] + IntegerPart[IntegerPart[y/100]/4]; > > f = d + (h/24) + (m/(24*60)) + (s/(24*3600)); > > jd = IntegerPart[(365.25*(y + 4716))] + > IntegerPart[(30.6001*(m + 1))] + d + b - 1524.5; > > mjd = jd - 2400000.5; > > mjd > > ) > > julianDayModified[2010, 1, 1, 12, 0, 0] > > 55164. > > --------------------------------------------------------------------------------------------------------------- > Best > Herman > > On Tue, Jan 19, 2010 at 12:13 PM, Canopus56 <canopus56 at yahoo.com> wrote: > >> I took a stab at writing my first function - converting a system >> formatted >> list date into a Modified Julian Day. The function appears to be >> written >> properly, but does not return anything. >> >> Any help in debugging it would be appreciated. >> >> Ideally, I would like to send a date-time list in the form >> {y,m,d,h,m,s} to >> the function and have the Julian Day returned. >> >> Thanks for your help - Kurt >> >> (* This function computes the Modified Julian Day from a \ >> system formatted date. Domain is restricted to Greogorian dates. \ >> Source: Meeus. 1998. Chap. 7. Astronomical Alogrithms. *) >> (* fractionalize the day value *) >> >> JulianDayModified[y_, m_, d_, h_, m_, s_] := ( >> B = 2 - IntegerPart[y/100] + IntegerPart[IntegerPart[y/100]/4]; >> d = d + ((m * 60 )/ ( 24 * 60 )) + ((s * 3600)/(24 * 3600)); >> JD = IntegerPart[(365.25*(y + 4716))] + >> IntegerPart[(30.6001*(m + 1 ))] + d + b - 1524.5; >> MJD = JD - 2400000.5; >> MJD >> ) >> >> JulianDayModified[2010, 1, 1, 12, 0, 0] >> >> Returns the string " >> JulianDayModified[2010, 1, 1, 12, 0, 0]" >> >> and not the computed date >> >> Also tried it this way with the Module statement with no change in the >> result: >> >> JulianDayModified[y_, m_, d_, h_, m_, s_] := Module[{B, JD, MJD}, >> B = 2 - IntegerPart[y/100] + IntegerPart[IntegerPart[y/100]/4]; >> d = d + ((m*60)/(24*60)) + ((s*3600)/(24*3600)); >> JD = IntegerPart[(365.25*(y + 4716))] + >> IntegerPart[(30.6001*(m + 1))] + d + b - 1524.5; >> MJD = JD - 2400000.5; >> MJD >> ] >> > > > -- DrMajorBob at yahoo.com
- References:
- First function debug help
- From: Canopus56 <canopus56@yahoo.com>
- First function debug help