Tag Info

New answers tagged

3

rmQ = MatrixQ[#, Internal`RealValuedNumericQ] &; ClearAll[realB, real] real[m_ /; MatrixQ[m] && Norm[Im[m], \[Infinity]] == 0] := m realB[m_?rmQ] := m real[RandomReal[1, {3000, 3000}]] // Head // AbsoluteTiming (* {0.312443,List} *) realB[RandomReal[1, {3000, 3000}]] // Head // AbsoluteTiming (* {0.093755,List} *) See also: How to check if an ...


4

Update: after clarification I propose f[m_] := Block[{$Assumptions = Alternatives @@ Flatten@m ∈ Reals}, Conjugate[m[[1, 1]]] // Simplify] f[{{x, x^2}, {h[x], S[y]^2}}] (* x *) Previous test-based answer: From the documentation of MatrixQ Test if a matrix has real numeric entries: MatrixQ[{{Pi, Sin[1]}, {Cos[2], E}}, Im[#] == 0 &] ...


2

Maybe this will work for you. validNum = Except[_Complex, _?NumericQ]; f[m : {{validNum ..} ..}] := m f will accept a wide variety number forms but not complex numbers. f[{{1, 2.}, {3/4, π}, {5, 6}}] {{1, 2.}, {3/4, π}, {5, 6}} f[{{1 + I, 2.}, {3/4, π}, {5, 6}}] f[{{1 + I, 2.}, {3/4, π}, {5, 6}}] Nor will it accept forms that are not ...



Top 50 recent answers are included