Simplifying symbolic, trigonometric results in a matrix
2 views (last 30 days)
Show older comments
I'm actually in R2020
I've been working with symbolic operations in a robotics class and we've been having trouble getting concise results. First, the results were given in gigantic fractions, but managed to resolve this using a combination of both simplify() first, and then vpa(,2).
What is now a problem is that the results are really long. They have a bunch of terms (sine, cosine, all in a sum), but most of those terms are essentially zero.
Here is an example result in a 4 x 4 matrix:
6.1? โ 17 โ ?3 โ ???(?โ1) + ?2 โ ???(?โ1) โ ???(?โ2) + ?3 โ ???(?โ1) โ ???(?โ2) โ 6.1? โ 17 โ ?2 โ ???(?โ1) โ ???(?โ2) + 6.1? โ 17 โ ?6 โ ???(?โ1) โ ???(?โ5) + 6.1? โ 17 โ ?3 โ ???(?โ1) โ ???(?โ2) + 3.7? โ 33 โ ?3 โ ???(?โ2) โ ???(?โ1) โ 6.1? โ 17 โ ?3 โ ???(?โ1) โ ???(?โ2) + 2.3? โ 49 โ ?6 โ ???(?โ4) โ ???(?โ5) โ ???(?โ1) โ 1.0 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ5) โ 6.1? โ 17 โ ?6 โ ???(?โ2) โ ???(?โ1) โ ???(?โ5) โ 6.1? โ 17 โ ?6 โ ???(?โ4) โ ???(?โ1) โ ???(?โ5) โ 1.0 โ ?6 โ ???(?โ5) โ ???(?โ1) โ ???(?โ4) โ 1.4? โ 65 โ ?6 โ ???(?โ1) โ ???(?โ4) โ ???(?โ5) + 1.0 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5) โ 1.4? โ 65 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5) โ 2.3? โ 49 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ5) โ ???(?โ4) + 1.4? โ 65 โ ?6 โ ???(?โ1) โ ???(?โ4) โ ???(?โ5) โ ???(?โ2) + 8.6? โ 82 โ ?6 โ ???(?โ2) โ ???(?โ4) โ ???(?โ5) โ ???(?โ1) โ 6.1? โ 17 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5) โ 3.7? โ 33 โ ?6 โ ???(?โ1) โ ???(?โ4) โ ???(?โ2) โ ???(?โ5) โ 6.1? โ 17 โ ?6 โ ???(?โ1) โ ???(?โ5) โ ???(?โ2) โ ???(?โ4) โ 2.3? โ 49 โ ?6 โ ???(?โ2) โ ???(?โ4) โ ???(?โ1) โ ???(?โ5) โ 3.7? โ 33 โ ?6 โ ???(?โ2) โ ???(?โ5) โ ???(?โ1) โ ???(?โ4) โ 6.1? โ 17 โ ?6 โ ???(?โ4) โ ???(?โ5) โ ???(?โ1) โ ???(?โ2) โ 8.6? โ 82 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5) โ 5.3? โ 98 โ ?6 โ ???(?โ2) โ ???(?โ1) โ ???(?โ4) โ ???(?โ5) + 8.6? โ 82 โ ?6 โ ???(?โ4) โ ???(?โ1) โ ???(?โ2) โ ???(?โ5) + 1.4? โ 65 โ ?6 โ ???(?โ5) โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) + 3.7? โ 33 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5)
As you can see, the result has mostly terms in a
scale.
I had seen before in different excercises that when working with symbolics, MATLAB would express a 1 (which had to be 1) as 1.00000000000, which makes me wonder if MATLAB is having trouble generating concise values when working with trigonometry.
I tried also having "pi" as symbolic, but it didn't do much to the problem at hand. Format short does nothing too.
What I would like to do:
- Ideally, I'd like for MATLAB to calculate correctly these functions. As I know it may even be impossible for the program:
- Is there a way to tell MATLAB that any terms below a certain weight/value/relevance/idk be eliminated or considered 0?
This is my most recent code with said problem, the resulting matrix Mov has the problem. The values of interest are the ones in the last row, the first 3 are not of interest. The result shown above is the first term of this matrix (1,4), which, according to me, should be:
?2 โ ???(?โ1) โ ???(?โ2) + ?3 โ ???(?โ1) โ ???(?โ2)โ 1.0 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ5) + 1.0 โ ?6 โ ???(?โ1) โ ???(?โ2) โ ???(?โ4) โ ???(?โ5)
Code:
clear all, clc, close all
syms th1 th2 th3 th4 th5 th6 L1 L2 L6 T d3 pi
Rz1=[cos(th1) -sin(th1) 0 0; sin(th1) cos(th1) 0 0; 0 0 1 0; 0 0 0 1]%primer grado de libertad
Tr1=[1 0 0 0;0 1 0 0;0 0 1 L1;0 0 0 1]% traslacion L1 en Z
Rx1=[1 0 0 0;0 cos(-pi/2) -sin(-pi/2) 0;0 sin(-pi/2) cos(-pi/2) 0;0 0 0 1]%rotacion 90grados negativos en x
Rz2=[cos(th2) -sin(th2) 0 0; sin(th2) cos(th2) 0 0; 0 0 1 0; 0 0 0 1]%segundo grado de libertad
Rx2=[1 0 0 0;0 cos(pi/2) -sin(pi/2) 0;0 sin(pi/2) cos(pi/2) 0;0 0 0 1]%rotacion 90grados positivos en x
Tr2=[1 0 0 L2;0 1 0 0;0 0 1 0;0 0 0 1]% traslacion L2 en X
Rz3=[cos(pi/2) -sin(pi/2) 0 0; sin(pi/2) cos(pi/2) 0 0; 0 0 1 0; 0 0 0 1]%Rotacion 90 grados positivos en z
Rx3=[1 0 0 0;0 cos(pi/2) -sin(pi/2) 0;0 sin(pi/2) cos(pi/2) 0;0 0 0 1]%rotacion 90grados positivos en x
Tr3=[1 0 0 0;0 1 0 0;0 0 1 d3;0 0 0 1]% tercer grado de libertad
Rx4=[1 0 0 0;0 cos(-pi/2) -sin(-pi/2) 0;0 sin(-pi/2) cos(-pi/2) 0;0 0 0 1]%rotacion 90grados negativos en x
Rz4=[cos(th4) -sin(th4) 0 0; sin(th4) cos(th4) 0 0; 0 0 1 0; 0 0 0 1]%cuarto grado de libertad
Rz5=[cos(-pi/2) -sin(-pi/2) 0 0; sin(-pi/2) cos(-pi/2) 0 0; 0 0 1 0; 0 0 0 1]%Rotacion 90 grados negativos en z
Rx5=[1 0 0 0;0 cos(-pi/2) -sin(-pi/2) 0;0 sin(-pi/2) cos(-pi/2) 0;0 0 0 1]%rotacion 90grados negativos en x
Rz6=[cos(th5) -sin(th5) 0 0; sin(th5) cos(th5) 0 0; 0 0 1 0; 0 0 0 1]%quinto grado de libertad
Tr4=[1 0 0 L6;0 1 0 0;0 0 1 0;0 0 0 1]% traslacion L6 en X
Rz7=[cos(-pi/2) -sin(-pi/2) 0 0; sin(-pi/2) cos(-pi/2) 0 0; 0 0 1 0; 0 0 0 1]%Rotacion 90 grados negativos en z
Rx6=[1 0 0 0;0 cos(-pi/2) -sin(-pi/2) 0;0 sin(-pi/2) cos(-pi/2) 0;0 0 0 1]%rotacion 90grados negativos en x
Rz8=[cos(th6) -sin(th6) 0 0; sin(th6) cos(th6) 0 0; 0 0 1 0; 0 0 0 1]%sexto grado de libertad
Mov=vpa(simplify(Rz1*Tr1*Rx1*Rz2*Rx2*Tr2*Rz3*Rx3*Tr3*Rx4*Rz4*Rz5*Rx5*Rz6*Tr4*Rz7*Rx6*Rz8),2)
3 Comments
Answers (0)
See Also
Categories
Find more on Elementary Math in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!