Re: Re: Putting an If in my function
- To: mathgroup at smc.vnet.net
- Subject: [mg101108] Re: [mg101073] Re: Putting an If in my function
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Wed, 24 Jun 2009 06:32:52 -0400 (EDT)
- References: <h1neun$8rk$1@smc.vnet.net> <200906231106.HAA08214@smc.vnet.net> <20090623085416.51104n3qjb2plf28@web.mail.umich.edu>
Hi Porscha, Set (=) evaluates the right hand side immediately. At that time the truth of the condition g==w cannot be determined as these are still unknown parameters. You must use SetDelayed (:=) so that the condition will be evaluated at the time the function is called with known parameters. Cheers -- Sjoerd BTW the '==='in the last line of my reply should have been =!= > -----Original Message----- > From: Porscha Louise McRobbie [mailto:pmcrobbi at umich.edu] > Sent: 23 June 2009 14:54 > To: Sjoerd C. de Vries > Cc: mathgroup at smc.vnet.net > Subject: Re: [mg101073] Re: Putting an If in my function > > Hi, > > I'm also interested in adding a special case to a function. Using > what's written below works fine: > > myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w > > But why doesn't the same work when the myFun is defined using "=" > instead of":="? i.e., > > myFun[a_, g_, f_, x_, d_, w_] = (d + a f x) /; g == w > ln[5]:=myFun[a, w, f, x, d, w] > Out[5]=d + a f x /; w == w > > Thanks, > Porscha > > > Quoting "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>: > > > Dear lobotomy, > > > > "Nomen est omen", the old Romans used to say. And they were often > > right. > > > > I'm not sure what you are trying to do here, with your function in an > > unneccessary, overly complex, pure function notation. Why not write: > > > > myFun[a_, g_, f_, x_, d_, w_] := d (1 + (E^g - E^w)/f)^(f x) + (a (-1 > > + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w) > > > > which is much more readable (at least in Mathematica)? > > > > In[31]:= Limit[myFun[a, g, f, x, d, w], g -> w] > > > > Out[31]= d + a f x > > > > You use the undefined 'n' in d + a n. I guess this must be f x... > > > > You can add a definition for myFun for this special case like this > (no > > If[ ] necessary): > > > > myFun[a_, g_, f_, x_, d_, w_] := d + a f x /; g == w > > > > In[36]:= myFun[a, w, f, x, d, w] > > > > Out[36]= d + a f x > > > > If you want to use an If in the definition this would be something > > like: > > > > myFun[a_, g_, f_, x_, d_, w_] := If[g===w, d (1 + (E^g - E^w)/f)^(f= > > x) > > + (a (-1 + (1 + (E^g - E^w)/f)^(f x)) f)/( E^g - E^w),d + a f x] > > > > Cheers -- Sjoerd > > > > On Jun 22, 10:21 am, Lobotomy <labb... at gmail.com> wrote: > >> Hi, this is my function > >> > >> #5 (1 + ((E^#2 - 1) - (E^#6 - > >> 1))/#3)^(#3*#4) + (#1*((1 + (((E^#2 - 1) - (E^#6 = > > - > >> 1))/#3))^(#3*#4) - > >> 1))/(((E^#2 - 1) - (E^#6 - 1))/#3) &[a, g, f, x, d, w] > >> > >> in the case when w==g the denominator equals zero. > >> > >> in this case i would like to rewrite the formula above to the much > >> simpler > >> d+a*n. How is this done? I've tried > >> > >> If[w == g, % = d + a*n], but this is not working. Another thing is > >> where to put the "If" > > > > > > > > > >
- References:
- Re: Putting an If in my function
- From: "Sjoerd C. de Vries" <sjoerd.c.devries@gmail.com>
- Re: Putting an If in my function