In this question. I suggested that to test whether the input of a function was a matrix of numbers one could create the following test:
matrixnumQ[exp_] := MatrixQ[exp, NumericQ]
and then define the function as:
myfunction[W_?matrixnumQ]:=W
This is simple enough in this case but is there a way to test patterns on inputs in a single line if the pattern test is more complex than that above. Something like:
myfunction[W_?MatrixQ[#,NumericQ]&]:=W
This clearly doesn't work but just to give you the idea of what I'm looking for
Condition(/;) taking e.g.Det[W]as a definition, e.g.myfunction[W_ /; MatrixQ[W, NumericQ]] := Det[W]. This question should be interesting: http://mathematica.stackexchange.com/questions/533/placement-of-condition-expressions – Artes May 24 '13 at 01:01/;after finding it in another question. Your implementation is better though. If you want to write this as an answer, I'll accept it. – Jonathan Shock May 24 '13 at 01:02myfunction[W_?(MatrixQ[#,NumericQ]&)]. See this question for an explanation. If this was the main difficulty you had here, I'd consider this question a duplicate. – Leonid Shifrin May 24 '13 at 11:20