Using transpose versus ctranspose in MATLAB

When transferring vectors / matrices to MATLAB, I saw and used only the ' (apostropohe) operator for a long time.

For example:

 >> v = [ 1 2 3 ]' v = 1 2 3 

However, this is a conjugate transpose , as I recently learned, or ctranspose .

This, apparently, matters only in the presence of complex numbers, where, if you want to transfer the matrix without getting conjugation, you need to use the operand .' .

Is it good to use too .' for real matrices and vectors? What should we teach newcomers to MATLAB?

+25
arrays matrix matlab
Aug 05 '14 at 23:38
source share
4 answers

Interest Ask!

I would definitely say good practice to use .' when you just want to transpose, even if the numbers are real and therefore will have the same effect. The main reasons for this are:

  • Conceptual clarity : if you need to transpose, just transpose. Do not throw unnecessary conjugation. This is bad practice. You will get used to writing ' for transposition and you will not notice the difference. Once you write ' when to use .' . For probable illustrations of this, see this question or this .

  • The future is explosion proof . If one day in the future you apply your function to complex inputs, the behavior will suddenly change and it will be difficult for you to find the reason. Trust me, I know what I'm saying 1 .

Of course, if you use real inputs, but pairing will make sense for complex inputs, use ' . For example, if you are defining a point product for real vectors, it might be advisable to use ' because if you want to use complex inputs in the future, conjugate transposition will make more sense .

1 In my early days of Matlab, it took me a while to track down a specific problem in my code, which turned out to be caused by the use of ' when I should have used .' . What really upset me was that my professor said ' transpose means! He forgot to mention the conjugate and, therefore, my mistake. Lessons I Learned: ' Not .' ; and professors can tell you everything that’s just wrong :-)

+24
Aug 6
source share

My very biased opinion: most of the cases that I use ' are purely "formal", in other words, not related to mathematical calculations. Most likely, I want to rotate a vector similar to the index sequence 1:10 by 90 degrees.

I rarely use ' for matrices, since it is ambiguous - the first question you should answer is why you want to transpose?

If the matrix was initially defined in the wrong direction, I would rather determine the matrix in the correct direction, as it should be, but not rotate it later.

To transpose the matrix for mathematical computation, I explicitly use transpose and ctranspose . Because the code is easier to read (no need to focus on these tiny points) and debugging (no need to take care of the missing points). Complete the following tasks, such as a point product, as usual.

+12
Aug 6 '14 at 0:15
source share

This is actually a topic of debate among many MATLAB programmers. Some say that if you know what you are doing, then you can use ' if you know that your data is purely real and use it .' if your data is complex, However, some people (such as Luis Mendo ) advocate something you should definitely use .' all the time so you don't get confused.

This allows you to properly handle input to functions if the data that is expected for your inputs into these functions is complex. There is a time when complex transposition is required, such as calculating the squared magnitude of a complex vector. In fact, Loren Shure in one of his MATLAB digests (I don’t remember which one ...) stated that this was one of the reasons why a complex transposition was introduced.




My suggestion is what you should use .' always if your goal is to transfer data. If you want to do complex arithmetic, use ' and .' depending on what kind of operation / calculation you are doing. Obviously, Luis Mendo removed me a good practice.

+10
Aug 6 '14 at 0:12
source share

Two cases are distinguished here:

  • Taking transposition for non-mathematical reasons, for example, you have a function that processes data as arrays, not mathematical vectors, and you need your error-correcting input to get it in the expected format.
  • Taking transposition as a mathematical operation.

In the latter case, the situation should dictate what is right, and probably only one of the two options is correct in this situation. Most often, this will be a conjugate transpose transfer, which corresponds to ' , but there are times when you have to take direct transpose, and then, of course, you need to use it .' .

In the first case, I suggest not using the transpose operator. Instead, you should either use reshape or simply insist that the input code execute correctly and throw an error if it is not. This clearly distinguishes this instance of "computer science" from true mathematical cases.

-one
Sep 08 '16 at 13:58 on
source share



All Articles