 # Can you make Complex Numbers to look better?

Dear all Octave Developers,
I have define 3 Pauli matrices in Octave v5.2 and they are computed correctly by Octave. However, the 2nd Pauli matrix does not look well because it contains complex numbers. Would you please show complex number with zero parts in a more elegant way? That is the standard way of showing complex numbers RealPart+ImagPart. How do you want it to look instead?

PauliY is
(0 -i
i 0) Fwiw, in Matlab:

``````>> PauliY = [0 -i; i 0]

PauliY =

0.0000 + 0.0000i   0.0000 - 1.0000i
0.0000 + 1.0000i   0.0000 + 0.0000i
``````

and
[ 0 -i
i 0]

is the same as

[ 0 + 0i 0 - 1i
0 + 1i 0 + 0i ]

in a numerical tool like Octave or Matlab.

if you want to customize the display, you will need to manually control output, see for example:

In general, I think you might want to divide solving a problem in to two phases: 1) computation and 2) presentation. For computation, it doesn’t particularly matter what the display is as long as the calculations are performed quickly and accurately. Once you have the result, you can then work on the presentation so that they best communicate what you want. This is certainly the way I approach plotting where there is a big difference between the rough plot I do to see how the data is behaving and the final plot which contains meaningful axis labels, adjusted aspect ratios, a title, possibly annotations, etc.

The suggestion by @nrjank to write your own display routine to get exactly what you want seems reasonable.

Just to be open-minded, Octave does inspect the values and make display decisions in the case of floating point numbers and integers. When a floating point number has no traling digits after the decimal point we display only the integer portion of the number. This generally looks better. So

``````octave:4> x = [1 2 3]
x =

1   2   3

octave:5> x(1) += eps
x =

1.0000   2.0000   3.0000
``````

That particular convention makes Octave look better than Matlab which displays both the real and imaginary parts of the Pauli matrix with 5 significant figures always.

Even if a mode was added to Octave’s format command to suppress missing real or imaginary parts, the display routine would have to leave alignment room in case other entries had those values. I’m not sure the result would look very good. Consider

`````` x = [0, -10+15i; -10+2i, i]

x =
0        -10 + 15i
-10 +  2i         1i
``````

That looks odd to me and doesn’t convey the columns as well as the current display (although maybe it is still god enough)

``````x =

0 +  0i  -10 + 15i
-10 +  2i    0 +  1i
``````

Of course, maybe you could take the additional step of right justifying the real value if the imaginary value were missing. But then I think you risk confusing real and imaginary numbers.

``````x = [2 ; 10+2i; -5+i]
x =

2
10 +  2i
-5 +  1i
``````

The sum of that column vector looks like `5 + 5i` to me even though it is actually `7 + 3i`.

2 Likes