MathGroup Archive 2006

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

Search the Archive

Re: Function defined with If

  • To: mathgroup at
  • Subject: [mg71396] Re: Function defined with If
  • From: Bill Rowe <readnewsciv at>
  • Date: Thu, 16 Nov 2006 00:54:22 -0500 (EST)

On 11/15/06 at 6:43 AM, julian.aguirre at (Julian Aguirre) wrote:

>I am trying to define a function of the variables x, y through other
>quantities depending on x and y and the function If. A minimal
>example is

>a = x;
>b = y;
>f[ x_, y_ ] = If[ a < b, a, b ]
>If[ x < y, a, b ]

>How can I force Mathematica to return If[ x < y, x, y ], as I
>thought it would?

Simply define the function appropriately. There is little point 
in defining a function that takes arguments named x, y as you 
done above when none of the named arguments appear on the right 
hand side.

The following definition for f will do what you want provided x 
and y do not have defined values

f[x_, y_]:=If[x<y,x,y]

Note, x,y appear on both sides and the usage of SetDelayed ":=" 
rather than Set "=". In general, you will want to define 
functions with SetDelayed not Set.
To reply via email subtract one hundred and four

  • Prev by Date: Re: Mathematica 5.2 redraw errors with X and nvidia graphics card
  • Next by Date: Re: Binomial Distribution
  • Previous by thread: RE: Function defined with If
  • Next by thread: Re: Function defined with If