Re: how to build pattern for a square matrix of reals?
- To: mathgroup at smc.vnet.net
- Subject: [mg98402] Re: [mg98379] how to build pattern for a square matrix of reals?
- From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
- Date: Thu, 9 Apr 2009 05:52:34 -0400 (EDT)
- References: <200904080903.FAA23145@smc.vnet.net>
Add an ampersand and a couple of parentheses:
In[1]:= f[(m_)?(MatrixQ[#1, NumericQ] && SameQ @@ Dimensions[#1] & )] :=
"Good!"
In[2]:= f[RandomReal[{-1, 1}, {2, 2}]]
Out[2]= "Good!"
In[3]:= f[RandomReal[{-1, 1}, {2, 3}]]
Out[3]= f[{{0.7458917724579508, -0.9549183202849245, 0.010947478301726044},
{-0.14117283873516007, 0.6198728660624302, 0.07598523139890823}}]
Adriano Pascoletti
2009/4/8 <sagrailo at gmail.com>
> As in subject: how to build a pattern that will specify that given
> argument of a function has to be square matrix of reals? Tried with
> following for "square matrix" part:
> f[x_?MatrixQ[#] && Dimensions[#][[1]] == Dimensions[#][[2]]
> &] := ...
> but it doesn't seem to be working...
>
> Thanks.
>
- References:
- how to build pattern for a square matrix of reals?
- From: sagrailo@gmail.com
- how to build pattern for a square matrix of reals?