While going over Mathworks' 2D solution to a seven-body probelm (found here https://www.mathworks.com/help/matlab/math/solve-celestial-mechanics-problem-with-high-order-ode-solvers.html# ) the following is used, xDist = (x - x.'); where x is a row vector. My question is why the dot? I get the same result without it. That is (x - x') = (x - x.'). I have a lot of respect for the Mathworks folks so I'm wondering if I'm missing a subtlety here.

댓글 수: 4

Stephen23
Stephen23 2024년 5월 9일
"I'm wondering if I'm missing a subtlety here."
If by "subtlety" you mean completly different operators with different behaviors used in different situations, then yes, you are missing out on a major part of understanding MATLAB. If you cannot identify the differences between array operations and matrix operations then your code will very easily produce nonsense and you won't know why:
Ian Leslie
Ian Leslie 2024년 5월 10일
Stephen23,
I think you may have missed the point of my post. I understand the dot operator. My question was why it was being used as I described above when it doesn't have any effect. Perhaps my title should have been Why is this dot notation used in this particular case? or Why is this dot operator used in this particular case? Perhaps you should just try it for yourself and see what I mean.
Stephen23
Stephen23 2024년 5월 10일
편집: Stephen23 2024년 5월 10일
"I understand the dot operator."
MATLAB does not have a "dot operator" that modifies arithmetic operators. MATLAB has these operators:
and similarly, power and division operators.
For some reason beginners sometimes incorrectly imagine that MATLAB has some kind of magic dot operator. It doesn't.
"My question was why it was being used as I described above ..."
Because the writer of that code wanted to transpose something, and the transpose operator is the correct operator for transposing things. Using the correct operator performs the required operation and makes the intent clear.
"... when it doesn't have any effect."
There are lots of ways that code can be written that produce the same output: this does not mean that those ways are equivalent in efficiency or clarity or meaning or understanding. For some reason some beginners seem to use the complex conjugate transpose by default, and then only grudgingly use transpose when a situation forces them to. This is the reverse of what should happen. I have often seen code that would work quite well with complex numbers, only to fail because the user has used the complex conjugate transpose consistently.
If you use the complex conjugate transpose when you really want to transpose something, then you are using the wrong operator.
Steven Lord
Steven Lord 2024년 5월 10일
MATLAB does not have a "dot operator".
Actually, technically it does though I think most people don't really think of it that way (unless they're writing a class and need to implement indexing.) The dot operator (as described on this documentation page) is used for struct field access and object property/method access. You can't subclass struct so you can't control how it's used for struct field access, but you can control (as I linked above) how . works for property/method access in your classes.
MATLAB also has operators whose expressions start with a dot (like .*, .^, .', and .() to name a few.) In my experience these (at least the first three of those) are more frequently considered as operators by users.

댓글을 달려면 로그인하십시오.

 채택된 답변

Voss
Voss 2024년 5월 9일
편집: Voss 2024년 5월 9일

0 개 추천

.' is transpose, and ' is complex conjugate transpose, so when x is real, x.' and x' are the same.
Example, real x:
x = magic(2)
x = 2x2
1 3 4 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x.'
ans = 2x2
1 4 3 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
x'
ans = 2x2
1 4 3 2
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
isequal(x.',x')
ans = logical
1
Example, complex x:
x = magic(2)+1i
x =
1.0000 + 1.0000i 3.0000 + 1.0000i 4.0000 + 1.0000i 2.0000 + 1.0000i
x.'
ans =
1.0000 + 1.0000i 4.0000 + 1.0000i 3.0000 + 1.0000i 2.0000 + 1.0000i
x'
ans =
1.0000 - 1.0000i 4.0000 - 1.0000i 3.0000 - 1.0000i 2.0000 - 1.0000i
isequal(x.',x')
ans = logical
0
isequal(x.',conj(x'))
ans = logical
1

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

릴리스

R2023b

태그

질문:

2024년 5월 9일

편집:

2024년 5월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by