3-dimensional orthonormal rotation symbolical

5 次查看(过去 30 天)
I want to create symbolical 3-dimensional orthonormal rotation matrices for a pure rotation of phi_x, phi_y and phi_z.
But my code did not work i get this error: Error using sym/subsindex (line 953)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic
variables, and function body must be sym expression.
Maybe someone can have a look what I am doin wrong here
% Clean up
clc
clear all
close all
% Variable Definition
phi_x = pi/2;
phi_y = 0;
phi_z=pi;
% Define symbolic variables
syms phi_x phi_y phi_z
% Create Rotation around axis
R_x = [1 0 0
0 cos(phi_x) -sin(phi_x);
0 sin(phi_x) cos(phi_x)];
R_y = [ cos(phi_y) 0 sin(phi_y);
0 1 0;
-sin(phi_y) 0 cos(phi_y)];
R_z = [cos(phi_z) -sin(phi_z) 0;
sin(phi_z) cos(phi_z) 0;
0 0 1];
% Overall Orthonormal Rotation Matrix
R = R_x*R_y*R_z
R= R_x(phi_x) * R_y(phi_y) * R_z(phi_z);
R_A_B(pi,-pi/2,3*pi/2)
% Convert to Numerical
double(R_A_B)

回答(1 个)

John D'Errico
John D'Errico 2021-11-24
编辑:John D'Errico 2021-11-24
You have several misunderstandings here. First:
phi_x = pi/2;
phi_y = 0;
phi_z=pi;
% Define symbolic variables
syms phi_x phi_y phi_z
So what happened when you wrote those lines? First, you created DOUBLE variables, named phi_x, phi_y, phi_z. You gave them numerical values.
But then what does the syms line do? It ovewrites the existing variables, replacing them with new ones that no longer have the values you assigned. So at this point, phi_x is no longer pi/2. It is just a symbolic variable with an unknown value. It might be a complex number. It might be anything.
Next, just because you have a symbolic expression like R_x, does not mean you can then perform a direct substitution using R_x(phi_x). R_x is a symbolic expression, not a function that can be used for evaluation.
You can use tools like subs, to substitute a value for a symbolic variable. So this would work:
subs(R_x,phi_x,pi/2)
Or you could use a tool like matlabFunction to convert them into functions.
  1 个评论
Mark S
Mark S 2021-11-24
Thanks for your help. Anyway I have found now the function tranimate(R). With that I can draw the rotation (what I also wanted)

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by