Re: problem evaluating a function on a list
- To: mathgroup at smc.vnet.net
- Subject: [mg69882] Re: problem evaluating a function on a list
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Tue, 26 Sep 2006 05:21:30 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <efacrp$1vm$1@smc.vnet.net>
wtplasar at ehu.es wrote: > 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 your function Listable by adding the attribute of the same name to the symbol H. In[3]:= SetAttributes[H, Listable] In[4]:= H[xlist, -0.4, 0.1, 70] Out[4]= {I, I, I, I, I, I, I, I, I} Regards, Jean-Marc