MathGroup Archive 2009

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

Search the Archive

Re: how to build pattern for a square matrix of reals?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98430] Re: how to build pattern for a square matrix of reals?
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 9 Apr 2009 05:58:12 -0400 (EDT)

On 4/8/09 at 5:03 AM, sagrailo at gmail.com wrote:

>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...

You don't need the [#] after MatrixQ. Probably the simplest way
to achieve the behavior you want is to specify a condition after
the body of the function. For example,

f[x_?MatrixQ] := Tr[x] /; SameQ @@ Dimensions[x]

will compute the trace of any square matrix and be unevaluated
for any argument other than a square matrix.




  • Prev by Date: Re: how to build pattern for a square matrix of reals?
  • Next by Date: Re: Hyperlinks
  • Previous by thread: Re: how to build pattern for a square matrix of reals?
  • Next by thread: Re: how to build pattern for a square matrix of reals?