How to solve the error "Error using sqpInterface Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." Error occurred when calling NLP solver
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kamal
el 23 de En. de 2024
Comentada: Emmanouil Tzorakoleftherakis
el 28 de Feb. de 2024
Please I need help to resolve the "Error using sqpInterface Nonlinear constraint function is undefined at initial point. Fmincon cannot continue." Error occurred when calling NLP solver"
I follow the example "Swing-up control of a pendulum using nonlinear model predictive control" to design nonlinear model predictive for a system. I followed the example and adapted it to my system. I created all the files as given in the example. However, I am getting the error above each time i run the code. Nontheless, the exampe runs fine. I am wondering what could be causing the problem.
Here is the code:
nx=13;
ny=1;
nu=1;
nlobj=nlmpc(nx,ny,nu);
Ts=0.1;
nlobj.Ts=Ts;
nlobj.PredictionHorizon=10;
nlobj.ControlHorizon=5;
nlobj.Model.StateFcn="Holos_microreactorDT0";
nlobj.Model.IsContinuousTime = false;
nlobj.Model.NumberOfParameters = 1;
nlobj.Model.OutputFcn = 'Holos_microreactorOutputFcn';
nlobj.Jacobian.OutputFcn = @(x,u,Ts) [1 0 0 0 0 0 0 0 0 0 0 0 0];
nlobj.Weights.OutputVariables = 3;
nlobj.Weights.ManipulatedVariablesRate = 0.1;
nlobj.OV.Min = -10;
nlobj.OV.Max = 150;
nlobj.MV.Min = -0.145;
nlobj.MV.Max = 0.145;
x0 = [0.6;0.1;0.1;0.1;0.1;0.1;0;0;0;0;0;0;0];
u0 = 0.1;
validateFcns(nlobj,x0,u0,[],{Ts});
EKF = extendedKalmanFilter(@Holos_microreactorStateFcn, @Holos_microreactorMeasurementFcn);
x = [1;0;0;0;0;0;0;0;0;0;0;0;0];
y = x(1);
EKF.State = x;
mv = 0;
yref = 0.8;
nloptions = nlmpcmoveopt;
nloptions.Parameters = {Ts};
Duration = 20;
hbar = waitbar(0,'Simulation Progress');
xHistory = x;
for ct = 1:(20/Ts)
% Set references
%if ct*Ts<10
yref;
%else
%yref = yref2;
%end
% Correct previous prediction using current measurement.
xk = correct(EKF, y);
% Compute optimal control moves.
%z=[0 0 0 0 0 0 0 0 0 0 0 0 0 ]'
[mv,nloptions,info] = nlmpcmove(nlobj,xk,mv,yref,[],nloptions);
% Predict prediction model states for the next iteration.
predict(EKF, [mv; Ts]);
% Implement first optimal control move and update plant states.
x = Holos_microreactorDT0(x,mv,Ts);
% Generate sensor data with some white noise.
y = x(1) + randn(1)*0.01;
% Save plant states for display.
xHistory = [xHistory x]; %#ok<*AGROW>
waitbar(ct*Ts/20,hbar);
end
close(hbar)
My system has 13 states, single output and single input as given above.
I would appreciate your help, thank you
0 comentarios
Respuesta aceptada
Emmanouil Tzorakoleftherakis
el 24 de En. de 2024
The dynamics/state function are turned into constraints internally when creating a NLP for fmincon. You don't provide all the functions required to run the code so I am not 100% sure but I would guess the error comes from the state function itself. Maybe put a break point and check the output of this function for the specific (x,u) pair that creates the problem.
11 comentarios
Emmanouil Tzorakoleftherakis
el 28 de Feb. de 2024
Np. Can you please post a separate question for this? Otherwise it will get lost in this thread.
Thanks!
Más respuestas (1)
Torsten
el 23 de En. de 2024
Before calling "fmincon", call the constraint function with your initial vector. My guess is that it returns NaN or Inf for some equality/inequality constraints.
3 comentarios
Torsten
el 23 de En. de 2024
Editada: Torsten
el 23 de En. de 2024
It seems your problem is internally transformed and handed to "fmincon". I don't know how to find the reason for failure if the objective and constraint functions that were internally generated cannot be made accessible from your code. Maybe it's possible, but I have no experience with the MPC Toolbox.
Ver también
Categorías
Más información sobre Refinement en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!