Re: Yet another simple question.

• To: mathgroup at smc.vnet.net
• Subject: [mg48127] Re: Yet another simple question.
• From: Thomas Burton <tburton at brahea.com>
• Date: Fri, 14 May 2004 00:12:26 -0400 (EDT)
• Organization: Brahea Consulting
• References: <c438uh\$emi\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Fri, 26 Mar 2004 21:02:41 -1000, George wrote
(in message <c438uh\$emi\$1 at smc.vnet.net>):

> fff[day_] = Mod[day + 2*mr + Quotient[3*(mr + 1), 5] + yr + 2 + Quotient[yr,
> 4] + Quotient[yr, 400] - Quotient[yr, 100], 7];
>  ...
> Do[Q = Which[fff[x] == 1, x], {x, D + 1, D + 7, 1}]

Examine the on-line help for Which. You'll see that you would need to embed
the Do loop inside Which, not outside as you have it. The problem with that
is, Do doesn't produce  output! Instead of Do, you need Table or Range. But
even so, getting the output of Table or Range into the correct form for Which
is a bit tough for a new user.  Select is much easier to use in this
application:

In[83]:=
Block[{mr = 1, yr = 2, D = 3},
Select[Range[D + 1, D + 7], fff[#1] == 1 & ]
]
Out[83]=
{8}

(Read about With, Module, & Block to see why I chose Block.) I recommend the
Boolean function

In[84]:=
f1[day_] = fff[day] == 1
Out[84]=
Mod[2 + day + 2 mr + yr + Quotient[3 (1 + mr), 5] +
Quotient[yr, 4] - Quotient[yr, 100] + Quotient[yr, 400],
7] == 1

to simplify the expression within Select:

In[85]:=
Block[{mr = 1, yr = 2, D = 3},
Select[Range[D + 1, D + 7],  f1]
]
Out[85]=
{8}

We are using prompt assignments (fff = ...) and getting away with it. Until
you are more familiar with Mathematica, however, I recommend delayed
assignments (fff := ...) to functions of one or more arguments.

Finally, as with several other single capital letters, the symbol D is
reserved in the System context.  (Type "?D" to see.) So you are overriding
it.  A better choice would be "d". If you must use "D", I suggest (a)
changing it's first reference to

`D    ,  where the first symbol is the left-handed apostrophe

and (b) reading about Contexts so you know what this means. But as I say,
it's simpler to use "d" instead.

Tom Burton

```

• Prev by Date: Re: Re: Uniform design
• Next by Date: nonlinear theory of elasticity question using Mathematica
• Previous by thread: RE: Selecting by first element of each list