Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts

1 回表示 (過去 30 日間)
Hello, I'm fairly new to MATLAB and I am unsure as to why my code came up with this error. This was part of the error message:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in evalcontrol (line 9)
u(:,ii)=-sys.r\sys.b'*reshape(deval(solp,Tf-t),length(x),length(x))*x;
Error in ACS420_3 (line 37)
[u,J,Jf]=evalcontrol(tspan,sys_name,solx,solp,Tf);
My parameters are as follows, and are in a function called imresp.m:
function sys=imresp(t,x)
a11=1; a12=1; a23=1; a31=1; a42=1; b2=1; b3=1;
b1=-1; b4=-1;
a22=3;
a32=1.5;
a33=0.5; a41=0.5;
f11=1; f44=1; q11=1; q44=1; r11=1; r22=1;
x2bar=2; x3bar=a31*x2bar/a32;
if nargin==0; sys.f = [f11 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 f44]; sys.xe = [0 x2bar x3bar 0]';
else
sys.a = [((a11-a12*x3bar)-a12*x(3)) 0 0 0;...
a21(x(4))*a22*(x(3)+x3bar) -a23 0 0;...
-a33*x3bar a31 -(a32+a33*x(1)) 0;...
a41 0 0 -a42];
sys.b = [b1 0 0 0; 0 b2 0 0]';
sys.q = [q11 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 q44];
sys.r = [r11 0; 0 r22];
end
and evalcontrol.m is:
function [u,J,Jf]=evalcontrol(tspan,sys_name,solx,solp,Tf)
xf=deval(solx,Tf);
tmp=zeros(1,length(tspan));
u=zeros(1,length(tspan));
for ii=1:length(tspan)
t=tspan(ii);
x=deval(solx,t);
sys=feval(sys_name,t,x);
u(:,ii)=-sys.r\sys.b'*reshape(deval(solp,Tf-t),length(x),length(x))*x;
tmp(ii)=x'*sys.q*x+u(:,ii)'*sys.r*u(:,ii);
end
J=cumtrapz(tspan,tmp)/2; % cumtrapz - cumulative trapezoidal numerical integration
sys=imresp2;
Jf=0.5*xf'*sys.f*xf;
Help is much appreciated. Thank you!
  6 件のコメント
Walter Roberson
Walter Roberson 2018 年 4 月 23 日
Looks like we still need imresp2
chromaclouds
chromaclouds 2018 年 4 月 23 日
編集済み: chromaclouds 2018 年 4 月 23 日
oops sorry, imresp2 is imresp. I forgot to change the name of the file. everything that is 'imresp2' is actually 'imresp' (in evalcontrol and ACS420_3).

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 23 日
In imresp you have
sys.b = [b1 0 0 0; 0 b2 0 0]';
that forces sys.b to be 4 x 2. When you work with in in evalcontrol in
u(:,ii)=-sys.r\sys.b'*reshape(deval(solp,Tf-t),length(x),length(x))*x;
then that forces there to be two rows of output. The various 1 x 4 and 4 x 4 cancel out effectively to make the number of columns of sys.b the control over the number of rows of result.
So the right hand side ends up being 1 x 2, being stored into column #ii of u. And that is a problem because you initialized
u=zeros(1,length(tspan));
so u only has one row, but you are trying to store two rows.
If you just change to
u=zeros(2,length(tspan));
then the code will proceed on to some plots.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel Predictive Control Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by