       Re: How to test if list of arguments are numeric

• To: mathgroup at smc.vnet.net
• Subject: [mg89521] Re: How to test if list of arguments are numeric
• From: Albert Retey <awnl at arcor.net>
• Date: Wed, 11 Jun 2008 05:15:41 -0400 (EDT)
• References: <g2nu84\$ej1\$1@smc.vnet.net>

```Michael A. Gilchrist wrote:
> Hi all,
>
> I'm trying to use a function with NMinimize and running into problems with
> holding off its evaluation until NMinimize passes real values.  Essentially, I
> have something like this
>
> TestFunction[avec_]:=Module[{},
> .
> .
> .
> ]
>
> Where avec should be a list of real numbers.  I know that to ensure avec is a
> list I use avec_?ListQ, but I need to ensure that avec is a list of real
> numbers (not the symbols that NMinimizes passes).
>
> Unfortunately, I have no idea what the correct syntax is.  Could someone
> please clue me in on this?

These two should work:

ClearAll[avec];
avec[x_?(VectorQ[#,NumericQ]&)]:=Row[{"Match: ",x}]

ClearAll[avec];
avec[x:{__?NumericQ}]:=Row[{"Match: ",x}]

These were my testcases:

avec
avec[a]
avec[{{}, a}]
avec[{1, 2, d}]
avec[{1, 2, 3, \[Pi]}]

be sure to ClearAll before redefining, otherwise the old definitions
will still be active!

hth,

albert

```

• Prev by Date: Re: How to test if list of arguments are numeric
• Next by Date: Re: How to test if list of arguments are numeric
• Previous by thread: Re: How to test if list of arguments are numeric
• Next by thread: Re: How to test if list of arguments are numeric