Assuming that this is required only for formatting purposes, as it was in this seemingly identical question (I cannot decide which of these should be closed as the duplicate of the other, and would be grateful if someone could help me do so), then I would like to provide another approach in addition to what has been proposed so far. It seems to me that the other answers suffer variously from the following problems:
Modifying core system symbols (Complex
)
Changing the structure of the expression and not only its presentation
Adding wrappers that make the formatted expression unusable in further computations without their prior removal
Requiring application to individual expressions rather than consistently changing how these numbers are displayed within a session
Retaining the parentheses that appear around e.g. (0. + 1. I)*2
, but which are superfluous when this is changed to (1. I)*2
Not correctly observing the Orderless
property of e.g. Plus
and Times
This is not meant to denigrate the other answers, but I think we can do much better in just a few lines:
(* format rule for Complex[0., im_] as im I *)
MakeBoxes[Complex[0., im_], form_] := MakeBoxes[im I, form];
(* prevent now-unnecessary parentheses when this is part of another expression*)
MakeBoxes[h_[pre___, z : Complex[0., _], post___], form_] :=
Module[{placeholder},
MakeBoxes[h[pre, placeholder, post], form] /.
MakeBoxes[placeholder, form] -> MakeBoxes[z, form]
];
Tests:
0. + I (* -> 1. I *)
(0. + I) x (* -> 1. I x *)
(1. + 1. I) x (* -> (1. + 1. I) x *)
(0. + I) x Exp[(0. + 2. I) y-(0. + 3. I) z] (* -> 1. I E^(2. I y-3. I z) x *)
a = (0. + I) x; 7 a (* -> 7. I x *)
((0. + I) + (1. + 0. I ) x) Exp[y] (* -> E^y (1. I + (1. + 0. I) x) *)
mymatrix (*from the question*) // Chop // MatrixForm
mymatrix // Chop // Det
(* -> -0.333333 I + 0.57735 I E^(-0.866026/t) + 0.57735 I E^(-0.366026/t) *)
It seems to work reasonably well. I can't think of any possible issues with it, but would be happy for someone to point them out, if they exist.
Chop
under "Possible issues". It says that machine complex numbers always have machine real values for both the real part and the imaginary part, therefore the zero cannot be removed. $\endgroup$