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

조회 수: 22 (최근 30일)
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

채택된 답변

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2024년 1월 24일
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
Kamal
Kamal 2024년 2월 27일
here is the correct model and some of the outputs generated. I have attached the correct model as well as a good simulation result i got. I have not been able to implement the simulink version. Thnak you
Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2024년 2월 28일
Np. Can you please post a separate question for this? Otherwise it will get lost in this thread.
Thanks!

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

추가 답변 (1개)

Torsten
Torsten 2024년 1월 23일
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
Torsten
Torsten 2024년 1월 23일
편집: Torsten 2024년 1월 23일
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.
Kamal
Kamal 2024년 1월 23일
@Torsten Thank you. Yeah the problem is implict because there is no fmicon in my code. However, I believe the nmpc function needs to call its own execution.

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

카테고리

Help CenterFile Exchange에서 Refinement에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by