# Multiple pattern test in the definition of a function

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.

## 1 Answer

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.

• I had tried something like this, but without the parenthesis. This works, thanks! – bnado Apr 29 '16 at 12:52