# 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

11 views (last 30 days)

Show older comments

Kamal
on 23 Jan 2024

Commented: Emmanouil Tzorakoleftherakis
on 28 Feb 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 Comments

### Accepted Answer

Emmanouil Tzorakoleftherakis
on 24 Jan 2024

##### 11 Comments

Emmanouil Tzorakoleftherakis
on 28 Feb 2024

Np. Can you please post a separate question for this? Otherwise it will get lost in this thread.

Thanks!

### More Answers (1)

Torsten
on 23 Jan 2024

##### 3 Comments

Torsten
on 23 Jan 2024

Edited: Torsten
on 23 Jan 2024

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!