MathGroup Archive 2009

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

Search the Archive

Conditional evaluations of functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96485] Conditional evaluations of functions
  • From: Asim <maa48 at columbia.edu>
  • Date: Sat, 14 Feb 2009 03:12:34 -0500 (EST)

Hi

I am not sure why the function g does not work, but the function f
works as expected on Mathematica 7.0 on Windows XP.  I want to get the
sum of a vector only if the argument supplied is a numeric vector.

In[1]:= g[x_?VectorQ[ x, NumericQ]] := Total[x]

In[2]:= g[{a, b , c}]

Out[2]= g[{a, b, c}]

In[3]:= g[{1, 2, 3}]

Out[3]= g[{1, 2, 3}]

In[4]:= f[x_ /; VectorQ[x, NumericQ]] := Total[x]

In[5]:= f[{a, b, c}]

Out[5]= f[{a, b, c}]

In[6]:= f[{1, 2, 3}]

Out[6]= 6

I also found different behavior for the function g, in Mathematica
6.0, which also was not what I wanted.

Thanks

Asim


  • Prev by Date: Re: testing if a point is inside a polygon
  • Next by Date: Re: Laplace Transform Exponential Shift
  • Previous by thread: Re: Re: Functions inside modules with external definitions
  • Next by thread: Re: Conditional evaluations of functions