MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Integer designation



blimbaum_jerry@ccmail.ncsc.navy.mil wrote:
> On page 261 of the 3rd edition of
> Mathematica
>      it talks about making an integer assignment, i.e. "f[n_Integer] is
>      like defining a function f that must take an argument of "type"
>      Integer.   I try this in a function like f[x_,n_Integer]:=Sin[n Pi
>      (x/a)] and then type f[a,n] and expect the answer zero but it just
>      gives me Sin[n Pi].  What have I misunderstood here?
> 
>      thanks.  Jerry Blimbaum    US Navy Lab,   Panama City, Florida

Jerry:

In[2]:=
f[x_,n_Integer]:=Sin[n Pi (x/a)] 

Means:
"change f[x,n] to Sin[ n Pi (x/a)] if and only if n is an integer (has
head Integer)" 

In[3]:=

f[x,2/3]

Out[3]=
     2
f[x, -]
     3

In[4]:=
f[x, 5]

Out[4]=
    5 Pi x
Sin[------]
      2

This will give zero iff x is an even integer.

x_ is a form with name x that is matched by any expression n_Integer is
a form with name n that is matched by any expression with head Integer
(it does not mean that n *is* an integer).

It ia usefull to see the full form of expressions when trying to
understand behaviour.

In[5]:=
FullForm[x_]

Out[5]//FullForm=
Pattern[x, Blank[]]

In[7]:=
FullForm[n_Integer]

Out[7]//FullForm=
Pattern[n, Blank[Integer]]

-- 
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642



  • Prev by Date: Re: vectors in polar coordinates
  • Next by Date: Re: Maintaining values of variables
  • Prev by thread: Re: Integer designation
  • Next by thread: Vectors and Mathematica