Re: problem evaluating a function on a list

*To*: mathgroup at smc.vnet.net*Subject*: [mg69903] Re: problem evaluating a function on a list*From*: Peter Pein <petsie at dordos.net>*Date*: Wed, 27 Sep 2006 06:04:25 -0400 (EDT)*References*: <efacrp$1vm$1@smc.vnet.net>

wtplasar at ehu.es schrieb: > Hi everyone, > > I have to ask for your advise once again. > > I have this function > > H[x_, om_, > or_, H0_] := If[Im[om - 4*om^(2/3)*or^(1/3) + 2* > or + 2*Sqrt[or]*Sqrt[om + or]] == 0. && -1 + om - 4*om^(2/3) > *or^(1/ > 3) + 2*or + 2*Sqrt[or]*Sqrt[om + or] < 0, H0*((1 - om - > 2*or - 2* > Sqrt[or]*Sqrt[om + or])*(1 + x)^2 + (Sqrt[or] + Sqrt[or + om*(1 > + > x)^3])^2), I] > > and I want to evaluate it at a list > > xlist = {0.09, 0.17, 0.27, 0.4, 0.88, 1.3, 1.43, 1.53, 1.75}; > > When I choose parameters so that a list of real values should be > obtained everything seems to be fine as one can see if for instance we > evaluate > > H[xlist, 0.4, 0.1, 70] > > (my result is {81.138, 92.4217, 108.473, 132.803, 261.891, 435.859, > 503.238, 559.829, 699.774}) > > whereas in the cases I would expect the result to be > {I,I,I,I,I,I,I,I,I} > > I get simply one single > > I > > instead, as one can see from evaluation of > > H[xlist, -0.4, 0.1, 70]. > > Can someone indicate why this happens, and how I can get the > desired list which looks like {I,I,I,I,I,I,I,I,I}? > > Thanks in advance for your time, > > Ruth > > Hi Ruth, make use of the attribute "Listable": In[3]:= SetAttributes[H, Listable] In[4]:= H[xlist, 0.4, 0.1, 70] Out[4]= {81.1379736408618, 92.42173206211797, 108.47334023428536, 132.80319561373202, 261.89137559629944, 435.85854432074075, 503.2378317813145, 559.8294132419585, 699.7740480067278} In[5]:= H[xlist, -0.4, 0.1, 70] Out[5]= {I, I, I, I, I, I, I, I, I} Peter