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

조회 수: 7 (최근 30일)
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
Walter Roberson
Walter Roberson 2025년 3월 31일
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 2025년 4월 1일
All right, thank you for your help. I try to understand the reason for this early termination

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by