Re: problems with the definition of a function

• To: mathgroup at smc.vnet.net
• Subject: [mg36668] Re: [mg36651] problems with the definition of a function
• From: Murray Eisenberg <murraye at attbi.com>
• Date: Wed, 18 Sep 2002 02:09:56 -0400 (EDT)
• Organization: Mathematics & Statistics, Univ. of Mass./Amherst
• References: <200209160434.AAA07065@smc.vnet.net>
• Reply-to: murray at math.umass.edu
• Sender: owner-wri-mathgroup at wolfram.com

```The same principles that allow particular cases for defining a function
of a single variable would apply here, because Mathematica applies
particular rules before it applies general ones.  For example:

f[0, y_] := 0
f[2 Pi, y_] := y - 2
f[4 Pi, y_] := y - 4
f[x_, y_] := x^2 + y^3

This will do exactly what it looks like it does!

If you have a general family of particular cases, say at all even
integral multiples of Pi, then you could use something like the
following in place of the first three lines above:

f[k_ Pi, y_] := y - k /; IntegerQ[k] && EvenQ[k]

There are variants as to where to place the "condition" IntegerQ[k] &&
EvenQ[k], for example:

f[k_ Pi , y_] /; IntegerQ[k] && EvenQ[k] := y - k

f[k_ Pi /; IntegerQ[k] && EvenQ[k], y_] := y - k

fabio bagarello wrote:
> Hi there!!
> I have quite an easy and annoying problem with mathematica:
> I need to define a function f(x,y) which takes some values for
> x=0,2pi,4pi (indepently of y) and has a different expression for all
> the other values of y. This is easily done for one-dimensional
> functions but I am in serious troubles for my two-dimensional problem:
> any suggestion?
> Thanks a lot,
> Fabio
>
>
>

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street
Amherst, MA 01375

```

• Prev by Date: Re: Postponing loading of Package
• Next by Date: Plotting one point at a time with JLink
• Previous by thread: RE: problems with the definition of a function
• Next by thread: Converting Between Bases