Error while executing mpc algorithm in MATLAB

4 views (last 30 days)
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);

Accepted Answer

Walter Roberson
Walter Roberson on 2 Oct 2022
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 Comment
Walter Roberson
Walter Roberson on 2 Oct 2022
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()

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!