Why is this dot notation used?

7 views (last 30 days)
Ian Leslie
Ian Leslie on 9 May 2024
Edited: Stephen23 on 10 May 2024
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 Comments
Stephen23
Stephen23 on 10 May 2024
Edited: Stephen23 on 10 May 2024
"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 on 10 May 2024
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.

Sign in to comment.

Accepted Answer

Voss
Voss on 9 May 2024
Edited: Voss on 9 May 2024
.' 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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!