How to remove commutativity from symbolic multiplication
Show older comments
Hello, I am attempting to multiply two 4th dimensional vectors with varying coefficients depending on inputs, however I do not have commutivity in this scenario. It seems that MATLAB is assuming there is, is it possible to bypass this using symbolic variables or otherwise?
The code I'm using is attached. I am multiplying q_1 and q_2 and each of the symbolic substitutions (subs) are rules I am applying i.e
and
.
2 Comments
James Tursa
on 15 Feb 2020
To be clear, you are trying to implement quaternion multiplication symbolically, and the quaternion i, j, and k multiplication is not commutative ... they behave like the cross product rule.
Been there, done that (or tried to do that), and gave up myself ...
If you ever figure out a reasonable way to do it without rewriting all the symbolic stuff from scratch you deserve a gold star and I will buy you lunch!
Walter Roberson
on 15 Feb 2020
Quaternions are built in to the symbolic engine, https://www.mathworks.com/help/symbolic/mupad_ref/dom-quaternion.html
You would need to use evalin(symengine) or feval(symengine) to access those functions. And the results might potentially mess up the display interface :(
Accepted Answer
More Answers (1)
Ahallya Jaladeep
on 7 Mar 2022
0 votes
A simpler solution is to define your symbols as matrices. This will remove commutativity.
Example:
syms Ip Im Ix Iy Iz Sx Sy Sz Sp Sm E a b c r r1 r2 [2 2] matrix
Now all the defined symbols will be considered as 2*2 matrices and a*b is not equal to b*a.
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!