Error while executing mpc algorithm in MATLAB

조회 수: 1 (최근 30일)
Harshit Gupta
Harshit Gupta 2022년 10월 2일
댓글: Walter Roberson 2022년 10월 2일
While running drone_MPC.m getting the below error:-
Error using sym/cat>checkDimensions (line 68)
CAT arguments dimensions not consistent.
Error in sym/cat>catMany (line 33)
[resz, ranges] = checkDimensions(sz,dim);
Error in sym/cat (line 25)
ySym = catMany(dim, args);
Error in sym/horzcat (line 19)
ySym = cat(2,args{:});
Error in drone_MPC (line 95)
A=subs(JA,[x,u],[xe,ue]); A=eval(A);
Here is some part of the code(before which is running fine):-
syms x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12
syms u1 u2 u3 u4
xdot1=x4;
xdot2=x5;
xdot3=x6;
xdot4=(u1/m)*(x8+x9*x7)-kx*x4/m;
xdot5=(u1/m)*(x9*x8-x7)-ky*x5/m;
xdot6=(u1/m)-g-kz*x6/m;
xdot7=x10+x11*x7*x8+x12*x8;
xdot8=x11-x12*x7;
xdot9=x7*x11+x12;
xdot10=(u2/Ix)-((Iy-Iz)/Ix)*x11*x12;
xdot11=(u3/Iy)-((Iz-Ix)/Iy)*x10*x12;
xdot12=(u4/Iz)-((Ix-Iy)/Iz)*x10*x11;
xdot=[xdot1 xdot2 xdot3 xdot4 xdot5 xdot6 xdot7 xdot8 xdot9 xdot10 xdot11 xdot12].';
x=[x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12].';
u=[u1 u2 u3 u4].';
y=[x1 x2 x3 x9].';
[x_size,aux]=size(x);
[y_size,aux]=size(y);
[u_size,aux]=size(u);
ue=[m*g 0 0 0].';
xe=[x1 x2 x3 0 0 0 0 0 0 0 0 0].';
JA=jacobian(xdot,x.');
JB=jacobian(xdot,u.');
JC=jacobian(y, x.');
A=subs(JA,[x,u],[xe,ue]); A=eval(A); // this line getting error
B=subs(JB,[x,u],[xe,ue]); B=eval(B);
C=subs(JC,[x,u],[xe,ue]); C=eval(C);

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 2일
x=[x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12].';
u=[u1 u2 u3 u4].';
Those are column vectors of length 12 and 4.
A=subs(JA,[x,u],[xe,ue]);
The [x, u] is not just syntax: a real horzcat operation is done and the result is passed in that position. But one is length 12 and the other is 4, and it is not possible to have a matrix with different column lengths.
You need to use
A=subs(JA,[x;u],[xe;ue]);
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 10월 2일
Note that eval is not defined for symbolic expressions. It does something undocumented that is sometimes useful, but can also give unexpected answers. Do not use use eval there. Use double() instead of eval()

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by