6

I have a very simple question, and I'm sure there is a way to do this but I cannot find it:

if I want to create a function that's defined only for matrices, I can do it like this:

f[x_?MatrixQ]:=Det[x];

but what if I want to define a function which is defined only for matrices whose entries are numbers? I would like to combine MatrixQ with NumberQ for its matrix elements but I'm not sure how to make this work.

bnado
  • 413
  • 2
  • 8

1 Answers1

10

I was going for a syntactic pattern thing, but actually the two-argument form of MatrixQ should work here:

f[x_?(MatrixQ[#,NumberQ]&)]

MatrixQ[expr,test] gives True only if test yields True when applied to each of the matrix elements in expr.

LLlAMnYP
  • 11,486
  • 26
  • 65