don't get what solve should return as solution

1 次查看(过去 30 天)
Hi! I am new to symbolical equations in MATLAB. I have written the dynamics of a mobile inverted pendulum. The solution of the problem should be in this form: [ x y theta 0 0 0 0] but I get strange values. I have 3 solution per variable...I have attached the problem's parameters if someone were so nice to try the code.
%% Rappresentazione ISU
syms x y theta alpha dalpha v dtheta real
stato=[x y theta alpha dalpha v dtheta]';
syms dx dy dtheta dalpha ddalpha dv ddtheta real
d_stato=[dx dy dtheta dalpha ddalpha dv ddtheta]';
syms tau_r tau_l real
u=[tau_r tau_l]';
f1=v*cos(theta);
f2=v*sin(theta);
f3=dtheta;
f4=dalpha;
f5=(sin(2*alpha)*(b3*b1*(dtheta)^2-b5^2*(dalpha)^2)+(2*b5*b3*g*sin(alpha)))/(2*(b2*b3-b5^2*(cos(alpha)^2)));
f6=(sin(2*alpha)*(-b1*b5*(dtheta)^2*cos(alpha)-b5^2*g)+(2*b2*b5*(dalpha)^2*sin(alpha)))/(2*(b2*b3-b5^2*(cos(alpha)^2)));
f7=(-b1*dalpha*dtheta*sin(2*alpha))/(b4+b1*sin(alpha)^2);
f=[f1 f2 f3 f4 f5 f6 f7]';
T1=b2*b3-b5^2*(cos(alpha))^2;
T2=b4+b1*(sin(alpha))^2;
g5=b3*R+b5*cos(alpha);
g6=b2+(R*b5*cos(alpha));
g1=[0 0 0 0 -g5/(R*T1) g6/(R*T1) b/(R*T2)]';
g2=[0 0 0 0 -g5/(R*T1) g6/(R*T1) -b/(R*T2)]';
g=[g1 g2];
d_stato=f+g*u;
%% Risoluzione
assume(alpha<pi/2 & alpha>-pi/2)
eqns = [d_stato(1)==0 , d_stato(2)==0, d_stato(3)==0, d_stato(4)==0, d_stato(5)==0, d_stato(6)==0, d_stato(7)==0];
S= solve(eqns,[stato; tau_r; tau_l]','ReturnConditions',true);

采纳的回答

Walter Roberson
Walter Roberson 2021-8-8
%% Parametri
M_b=3.9;%Kg massa del pendolo
M_w=0.375;%Kg massa singola ruota
R=0.1025;%m raggio ruota
c_z=0.1;%m (0,0, c_z) centro di massa del pendolo rispetto al frame body pendolo
b=0.1620;%m
g=9.8;%N gravit
I_x=0.02;%Kg*m^2
I_y=0.015;%Kg*m^2
I_z=0.01;%Kg*m^2
I_wd=0.002;%Kg*m^2 momento di inerzia ruota attorno diametro
I_wa=0.001;%Kg*m^2 momento di inerzia ruota attorno asse di roll
%
b1=(M_b*c_z^2)+I_x-I_z;
b2=(M_b*c_z^2)+I_y;
b3=((M_b*R^2)+(2*(I_wa+M_w*R^2)))/R^2;
b4=R^2*(I_z+2*I_wd+2*b^2*M_w)+(2*b^2*I_wa);
b5=M_b*c_z;
%% Rappresentazione ISU
syms x y theta alpha dalpha v dtheta real
stato=[x y theta alpha dalpha v dtheta]';
syms dx dy dtheta dalpha ddalpha dv ddtheta real
d_stato=[dx dy dtheta dalpha ddalpha dv ddtheta]';
syms tau_r tau_l real
u=[tau_r tau_l]';
f1=v*cos(theta);
f2=v*sin(theta);
f3=dtheta;
f4=dalpha;
f5=(sin(2*alpha)*(b3*b1*(dtheta)^2-b5^2*(dalpha)^2)+(2*b5*b3*g*sin(alpha)))/(2*(b2*b3-b5^2*(cos(alpha)^2)));
f6=(sin(2*alpha)*(-b1*b5*(dtheta)^2*cos(alpha)-b5^2*g)+(2*b2*b5*(dalpha)^2*sin(alpha)))/(2*(b2*b3-b5^2*(cos(alpha)^2)));
f7=(-b1*dalpha*dtheta*sin(2*alpha))/(b4+b1*sin(alpha)^2);
f=[f1 f2 f3 f4 f5 f6 f7]';
T1=b2*b3-b5^2*(cos(alpha))^2;
T2=b4+b1*(sin(alpha))^2;
g5=b3*R+b5*cos(alpha);
g6=b2+(R*b5*cos(alpha));
g1=[0 0 0 0 -g5/(R*T1) g6/(R*T1) b/(R*T2)]';
g2=[0 0 0 0 -g5/(R*T1) g6/(R*T1) -b/(R*T2)]';
g=[g1 g2];
d_stato=f+g*u;
%% Risoluzione
assume(alpha<pi/2 & alpha>-pi/2)
eqns = [d_stato(1)==0 , d_stato(2)==0, d_stato(3)==0, d_stato(4)==0, d_stato(5)==0, d_stato(6)==0, d_stato(7)==0];
S= solve(eqns,[stato; tau_r; tau_l]','ReturnConditions',true);
S
S = struct with fields:
x: [3×1 sym] y: [3×1 sym] theta: [3×1 sym] alpha: [3×1 sym] dalpha: [3×1 sym] v: [3×1 sym] dtheta: [3×1 sym] tau_r: [3×1 sym] tau_l: [3×1 sym] parameters: [1×4 sym] conditions: [3×1 sym]
S.parameters
ans = 
S.x
ans = 
S.y
ans = 
S.theta
ans = 
S.conditions
ans = 
What this is telling you is that there are three families of solutions.
The first family says that x can be any arbitrary real number, and y is an arbitray real number (possibly different than x), and theta is any integer multiple of pi. In other words if theta is an integer multiple of pi, then a number of your terms vanish and so any arbitrary real x and y work.
The third family is nearly the same as the first, but theta is an odd half-integer multiple of pi; again that causes a lot of terms to vanish so it does not matter which real x and y you use.
The second family says that x and y and theta can all be arbitrary real values; possibly some of the other variables are tightly constrained, but you did not ask to look at those.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by