Borrar filtros
Borrar filtros

How to use of trigonometric identities in matlab?

24 visualizaciones (últimos 30 días)
Naseeb Gill
Naseeb Gill el 15 de Dic. de 2016
Respondida: Abdulsalam el 18 de Sept. de 2023
I want to do some matrix multiplication which include symbolic variables and sine and cosine function. Code is given below.
syms ('l1','th1''r11', 'r12', 'r13','r21', 'r22','r23','r31','r32','r33', 'px','py', 'pz');
A0_1 = [cos(th1) -sin(th1) 0 0 ; sin(th1) cos(th1) 0 0; 0 0 1 l1; 0 0 0 1];
EE = [r11 r12 r13 px; r21 r22 r23 py; r31 r32 r33 pz; 0 0 0 1] ;
inv1 = inv(A0_1)*EE;
Multiplied matrix include trigonometric identities like (cos(th1)^2 + sin(th1)^2) so I want to convert these trigonometric identities into its values like 1 in above case. How to do this?

Respuesta aceptada

Star Strider
Star Strider el 15 de Dic. de 2016
Use the simplify function:
syms l1 th1 r11 r12 r13 r21 r22 r23 r31 r32 r33 px py pz
A0_1 = [cos(th1) -sin(th1) 0 0 ; sin(th1) cos(th1) 0 0; 0 0 1 l1; 0 0 0 1];
EE = [r11 r12 r13 px; r21 r22 r23 py; r31 r32 r33 pz; 0 0 0 1] ;
inv1 = A0_1\EE;
inv2 = simplify(inv1)
inv2 =
[ r11*cos(th1) + r21*sin(th1), r12*cos(th1) + r22*sin(th1), r13*cos(th1) + r23*sin(th1), px*cos(th1) + py*sin(th1)]
[ r21*cos(th1) - r11*sin(th1), r22*cos(th1) - r12*sin(th1), r23*cos(th1) - r13*sin(th1), py*cos(th1) - px*sin(th1)]
[ r31, r32, r33, pz - l1]
[ 0, 0, 0, 1]
  4 comentarios
Naseeb Gill
Naseeb Gill el 15 de Dic. de 2016
Hello Star S. I have one little query here. If I want to substitute the values of l1 th1 r11 r12 r13 r21 r22 r23 r31 r32 r33 px py pz all these variables in my final matrix. How I should do?
Star Strider
Star Strider el 15 de Dic. de 2016
The easiest way is to use the matlabFunction function to create an anonymous function from ‘inv2’:
inv2_fcn = matlabFunction(inv2);
creating (after a little editing so it is on one line and a bit easier to read):
inv2_fcn = @(l1,px,py,pz,r11,r12,r13,r21,r22,r23,r31,r32,r33,th1) reshape([r11.*cos(th1)+r21.*sin(th1),r21.*cos(th1)-r11.*sin(th1),r31,0.0,r12.*cos(th1)+r22.*sin(th1),r22.*cos(th1)-r12.*sin(th1),r32,0.0,r13.*cos(th1)+r23.*sin(th1),r23.*cos(th1)-r13.*sin(th1),r33,0.0,px.*cos(th1)+py.*sin(th1),py.*cos(th1)-px.*sin(th1),-l1+pz,1.0],[4,4]);
then use it as you would any other function.

Iniciar sesión para comentar.

Más respuestas (1)

Abdulsalam
Abdulsalam el 18 de Sept. de 2023
how to write this equation?

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by