Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: problem evaluating a function on a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69888] Re: problem evaluating a function on a list
  • From: dh <dh at metrohm.ch>
  • Date: Tue, 26 Sep 2006 05:21:45 -0400 (EDT)
  • References: <efacrp$1vm$1@smc.vnet.net>

Hi Ruth,

your function has the form:

f[..]:=If[condition,..,I]

if the condition is false, I is returned. If the condition is true, 

things are a bit more complicated. You do some arithmetic with the 

argument x. By chance you only use Listable operators. Therefore, if you 

give a List as argument, your calculations return a List. On the other 

hand, had you used e.g. a function that is not Listable, say f, the 

result would not have been fully evaluated. In this case, you could use 

e.g. Map.



Daniel



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

> 

> 



  • Prev by Date: Re: problem evaluating a function on a list
  • Next by Date: RE: Copying cell contents?
  • Previous by thread: Re: problem evaluating a function on a list
  • Next by thread: Re: problem evaluating a function on a list