Error using horzcat Dimensions of arrays being concatenated are not consistent.

2 次查看(过去 30 天)
There is an error in the line with bold letters:
clear
Ad=[0.941 0.192; -0.576 0.903];
Bd=[.020; 0.192]; Gd=[.020; 0.192]; Sw=0.5;
Dx=[1 0;0 1;0 0]; Du=[0;0;1];
zmin=[-0.4; -1e6; -3]; zmax=[0.4; 1e6; 3];
nx=2;nu=1;nw=1;nz=3;
Q=[1 0;0 1]; R=0.5; S=[0; 0];
P=dare(Ad,Bd,Q,R);
L=inv(R+Bd'*P*Bd)*Bd'*P*Ad; Qf=P;
mpc=1; % set to zero for unconstrained LQOC
delay=0; % set to zero no delay
if(mpc == 1)
N=10; %horizon size
Mu=zeros(nu*N);Mx=zeros(nx*N);Mux=zeros(nu*N,nx*N);
for i=1:N-1
Mu(1+(i-1)*nu:nu+(i-1)*nu,1+(i-1)*nu:nu+(i-1)*nu)=R;
Mx(1+(i-1)*nx:nx+(i-1)*nx,1+(i-1)*nx:nx+(i-1)*nx)=Q;
Mux(1+i*nu:nu+i*nu,1+(i-1)*nx:nx+(i-1)*nx)=S';
end
Mu(1+(N-1)*nu:nu+(N-1)*nu,1+(N-1)*nu:nu+(N-1)*nu)=R;
Mx(1+(N-1)*nx:nx+(N-1)*nx,1+(N-1)*nx:nx+(N-1)*nx)=Qf;
M=[Mu Mux;Mux' Mx]; m=zeros((nu+nx)*N,1);
% Add Slack variables
M=[M zeros(N*(nx+nu),nz);zeros(nz,N*(nx+nu)) 0.0*eye(nz)]
m=[m; 1e6*[1; 1; 10]];
A0u=zeros(nx*N,nu*N);A0x=zeros(nx*N,nx*N);
A0u(1:nx,1:nu)=Bd; A0x(1:nx,1:nx)=-eye(nx);
for i=2:N
A0u(1+(i-1)*nx:nx+(i-1)*nx,1+(i-1)*nu:nu+(i-1)*nu)=Bd;
A0x(1+(i-1)*nx:nx+(i-1)*nx,1+(i-1)*nx:nx+(i-1)*nx)=-eye(nx);
A0x(1+(i-1)*nx:nx+(i-1)*nx,1+(i-2)*nx:nx+(i-2)*nx)=Ad;
end
A0=[A0u A0x]; b0=zeros(nx*N,1);
A0=[A0 zeros(nx*N,nz)]; % Add Slack variables
A1u=zeros(nz*N,nu*N); A1x=zeros(nz*N,nx*N); A1u(1:nz,1:nu)=Du;
b1max=zeros(nz*N,1); b1min=zeros(nz*N,1);
A1slack=zeros(nz*N,nz); % Add Slack variables
A1slack(1:nz,1:nz)=-eye(nz); % Add Slack variables
for i=2:N
A1u(1+(i-1)*nz:nz+(i-1)*nz,1+(i-1)*nu:nu+(i-1)*nu)=Du;
A1x(1+(i-1)*nz:nz+(i-1)*nz,1+(i-2)*nx:nx+(i-2)*nx)=Dx;
A1slack(1+(i-1)*nz:nz+(i-1)*nz,1:nz)=-eye(nz);
b1max(1+(i-1)*nz:nz+(i-1)*nz,1)=zmax;
b1min(1+(i-1)*nz:nz+(i-1)*nz,1)=-zmin;
end
A1=[A1u A1x;-A1u -A1x];
% Add Slack variables
A1=[A1 [A1slack; A1slack];zeros(nz,N*(nu+nx)) -eye(nz)];
end
Error using horzcat
Dimensions of arrays being concatenated are
not consistent.
Error in Untitled10 (line 26)
M=[M zeros(N*(nx+nu),nz);zeros(nz,N*(nx+nu)) 0.0*eye(nz)];
  8 个评论

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Model Predictive Control Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by