Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 17 de Abr. de 2018
It is not clear how your are invoking evalcontrol ?
The initialization code you give does not have a definition for x.
chromaclouds
el 17 de Abr. de 2018
Walter Roberson
el 23 de Abr. de 2018
I think we need all of ACS420_3.m .
You posted riccati and dynamics and imresp and evalcontrol already; if there is anything else beyond those and ACS420_3 then you should post the others as well.
chromaclouds
el 23 de Abr. de 2018
Walter Roberson
el 23 de Abr. de 2018
Looks like we still need imresp2
chromaclouds
el 23 de Abr. de 2018
Editada: chromaclouds
el 23 de Abr. de 2018
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Model Predictive Control Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!