在 MATLAB 中使用转置与 ctranspose [英] Using transpose versus ctranspose in MATLAB

查看:65
本文介绍了在 MATLAB 中使用转置与 ctranspose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MATLAB 中转置向量/矩阵时,我已经看到并使用了很长时间的 '(撇号)运算符.

When transposing vectors/matrices in MATLAB, I've seen and used just the ' (apostropohe) operator for a long time.

例如:

>> v = [ 1 2 3 ]'

v = 

    1
    2
    3

然而,这是我最近发现的共轭转置,或ctranspose.

However this is the conjugate transpose as I've recently found out, or ctranspose.

这似乎只在涉及复数时才重要,如果您想在不获得共轭的情况下转置矩阵,则需要使用 .' 运算符.

This seems to only matter when there are complex numbers involved, where if you want to transpose a matrix without getting the conjugate, you need to use the .' opertator.

然后将 .' 用于实矩阵和向量是否是一种好习惯?我们应该教 MATLAB 初学者什么?

Is it good practice to also use the .' for real matrices and vectors then? What should we be teaching MATLAB beginners?

推荐答案

有趣的问题!

我肯定会说,当您只想转置时,使用 .' 是一个好习惯,即使数字是真实的,因此 ' 也会有相同的效果.主要原因是:

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

  1. 概念清晰:如果您需要转置,只需转置即可.不要加入不必要的共轭.这是不好的做法.您会习惯于编写 ' 来转置,而不会注意到其中的区别.有一天你会在应该使用 .' 时编写 ' .作为这方面的可能说明,请参阅这个问题这个.

  1. Conceptual clarity: if you need to transpose, just transpose. Don't throw in an unnecessary conjugation. It's bad practice. You'll get used to writing ' to transpose and will fail to notice the difference. One day you will write ' when .' should be used. As probable illustrations of this, see this question or this one.

面向未来.如果将来有一天你将你的函数应用到复杂的输入中,行为会突然改变,你将很难找到原因.相信我,我知道我在说什么1.

Future-proofness. If one day in the future you apply your function to complex inputs the behaviour will suddenly change, and you will have a hard time finding the cause. Believe me, I know what I say1.

当然,如果您使用的是真实输入但共轭对复杂输入有意义,请使用 '.例如,如果您正在为实向量定义点积,则使用 ' 可能是合适的,因为如果您将来想使用复数输入,则共轭转置 会更有意义.

Of course, if you are using real inputs but a conjugation would make sense for complex inputs, do use '. For example, if you are defining a dot product for real vectors, it may be appropriate to use ', because should you want to use complex inputs in the future, the conjugate transpose would make more sense.

1 在我早期的 Matlab 时代,我花了很长时间来追溯代码中的某个问题,结果证明是使用了 ' 当我应该使用 .' 时.真正让我不安的是,实际上是我的教授说 ' 意味着转置!他忘了提到共轭,因此我的错误.我学到的教训:' 不是 .';教授可以告诉你一些完全错误的事情:-)

1 In my early Matlab days, it took me quite a while to trace back a certain problem in my code, which turned out to be caused by using ' when I should have used .'. What really got me upset is, it was my professor who had actually said that ' meant transpose! He forgot to mention the conjugate, and hence my error. Lessons I learned: ' is not .'; and professors can tell you things that are plain wrong :-)

这篇关于在 MATLAB 中使用转置与 ctranspose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆