Fmincon: Unable to perform assignment because the left and right sides have a different number of elements.

7 visualizaciones (últimos 30 días)
Hi, I could use some help please.
I’m working with the matlab optimizer to optimize a x0 speed profile (obtained by simulating a simulink model) respecting nonlinear constraints and a multi-objective J cost function (J = J1+J2+J3). To do this I use FMINCON-SQP-Forward.
x0 is of size 238 but I "extend" it to a fixed size of 300 samples (entering the last values at 0) to match it with the simulation time.
The optimizer starts running quietly and performs over 2000 Function Evaluation and 8/9 iterations, constraints improve but are not respected all of them, until it stops in the middle of an iteration, returning this error:
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in matlab.internal.optimfun.plotfcns.Factory/appendScalars (line 572)
data(ct) = optimValues.(dataFieldNames(ct));
Error in matlab.internal.optimfun.plotfcns.Factory>@(optimValues)matlab.internal.optimfun.plotfcns.Factory.appendScalars(optimValues,dataFieldNames) (line 753)
calculationFcn = @(optimValues) matlab.internal.optimfun.plotfcns.Factory.appendScalars(optimValues, dataFieldNames);
Error in matlab.internal.optimfun.plotfcns.AbstractPlotFunction/update (line 75)
data = this.CalculationFcn(optimValues, varargin{:});
Error in optimplotfirstorderopt (line 28) thePlot.update(optimValues);
Error in callAllOptimPlotFcns (line 137) state(i) = feval(plotNames{i},x,optimvalues,flag,varargin{:});
Error in sqpInterface Error in fmincon (line 672) [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = sqpInterface(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ... "
I don’t understand why:
1) Ceq = []
2) C = column vector with fixed dimension
3) x0 has a fixed dimension equal to simulation_time and the optimizer never stops before
4) I tried to disable the optimizer plots but nothing changes
5) The components of J are always defined and are scalar
  6 comentarios
Walter Roberson
Walter Roberson el 31 de Mzo. de 2025
It is likely that at some point your simulink model is ending early, probably complaining about an inability to integrate past a certain time. When this happens, the data returned by simulink will be the data up to the time the integration ended -- which will probably be shorted than the data that was returned before that point.
You need to avoid the situation where the integration ends early. Or at the very least you need to detect the situation and stop looping yourself.
Gabriele
Gabriele el 1 de Abr. de 2025
All right, thank you for your help. I try to understand the reason for this early termination

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by