       Re: small problem.

• To: mathgroup at smc.vnet.net
• Subject: [mg12929] Re: [mg12852] small problem.
• From: Sean Ross <seanross at worldnet.att.net>
• Date: Wed, 24 Jun 1998 03:44:47 -0400
• References: <199806170427.AAA17340@smc.vnet.net.>
• Sender: owner-wri-mathgroup at wolfram.com

```phpcp wrote:
>
> Hi!
>
> I want to choose a definition of a function by the vlaues of its
> argument. So I can use :
>
> a0[t_] := t^2 - t^3/5./;t<0.001;a0[t_] := t^2/;t>=0.001
>
> This works fine. But if the function definition (or form or whatever) is
> a bit more complicated as follows :
>
> solution = Solve[s0^4 + s0 t + 1 == 0,s0]; chi0[x_] :=
> x/;x<0.01;chi0[x_] := (solution[[3,1,2]]/.t -> x)/;x>=0.01
>
> It doesnt work. Any ideas?
>
> thanks in advance,
> Sanjay.

You can "overload" the definition of functions by specifying conditions
on the arguments in the formal parameter list itself.  For example:

myfunction[x_,y_/;(y<2.5&&y>-3.)]:=definition1
myfunction[x_,y_]:=definition2

In this case, whenever y was within the range -3 to 2.5, the first
function would execute and the second one would execute the rest of the
time.  You can also specify conditions on the dimensions, head, etc. of
the parameter.  For 2-D functions, I often put a condition like
a/;TensorRank[a]==2 , so that 1-D lists aren't included.  The only kind
of condition that doesn't seem to work in this manner is where one
parameter is compared against another.  You have to use an conditional
within the function to do that.

```

• Prev by Date: Re: How to plot list of items {x,y} where x is a scalar and y is an array.
• Next by Date: Re: Help: What is \Muserfunction generated with Splice?
• Previous by thread: small problem.
• Next by thread: Adding Menu Items to Front End