Re: Function defined with If
- To: mathgroup at smc.vnet.net
- Subject: [mg71396] Re: Function defined with If
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Thu, 16 Nov 2006 00:54:22 -0500 (EST)
On 11/15/06 at 6:43 AM, julian.aguirre at ehu.es (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 >In[1]:= >a = x; >b = y; >f[ x_, y_ ] = If[ a < b, a, b ] >Out[3]= >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