Why is this dot notation used?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Stephen23
le 10 Mai 2024
Modifié(e) : Stephen23
le 10 Mai 2024
"I understand the dot operator."
MATLAB does not have a "dot operator" that modifies arithmetic operators. MATLAB has these operators:
- .' is transpose
- ' is complex conjugate transpose
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
le 10 Mai 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.
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!