File Exchange

image thumbnail


version 1.4.2 (1.23 MB) by Robert Canfield
Sequential Linear Programming (SLP) with Trust Region (TR) and Sequential Quadratic Programming (SQP) with Line Search or TR Strategy


Updated 11 Oct 2020

View Version History

View License

Solve constrained, nonlinear, parameter optimization problems using sequential linear programming with trust region strategy (slp_trust), sequential quadratic programming with trust region strategy (sqp_trust), or sequential quadratic programming with line search (sqp), similar to fmincon in the Optimization Toolbox. SQP is a second-order method, following Schittkowski's NLPQL Fortran algorithm. SLP is a first-order method, but may be more efficient for large numbers of design variables. They are implemented using the original calling sequence of the obsolete MATLAB constr.m function in Version 1 of the optim toolbox, but may alternatively accept the problem data structure used by fmincon as an input argument. The original calling sequence had the advantage that one user function computed the objective and constraint values together, with a separate function for their gradients when finite differences were not used.

Complex-step derivatives, which can be accurate to machine precision, are a feature of sqp, slp_trust, and sqp_trust, in place of finite difference derivatives, when the user does not supply a function that computes the derivatives.

Compatible with Octave (MATLAB-compatible GNU Scientific Programming Language) <>.

Capt. Mark Spillman (USAF) wrote the original sqp.m code with me at AFIT.
Blake M. Van Winkle is gratefully acknowledged for initial Octave-compatible code.

Cite As

Robert Canfield (2020). slp_sqp (, MATLAB Central File Exchange. Retrieved .

Canfield, Robert A. “Quadratic Multipoint Exponential Approximation: Surrogate Model for Large-Scale Optimization.” Advances in Structural and Multidisciplinary Optimization, Springer International Publishing, 2017, pp. 648–61, doi:10.1007/978-3-319-67988-4_49.

View more styles

Schittkowski, K. “NLPQL: A Fortran Subroutine Solving Constrained Nonlinear Programming Problems.” Annals of Operations Research, vol. 5, no. 2, Springer Science and Business Media LLC, June 1986, pp. 485–500, doi:10.1007/bf02022087.

View more styles

Comments and Ratings (30)

D Kien Nguyen

Alain Barraud

some minor bugs before calling sqp. Using sqp directly I obtain almost the same results when compared to my mexfile of the Shittkowski fortran code.
Translating the original code in Matlab has surely been a difficult task (complexe fortran 77 go to structure).
A significative improvement would be to be independant of quadprog. It is the best matlab optimizer I known. I have successfully run several hundred of very difficult problems of modelisation with Schittowski solvers which are remained unsolved by most of well known codes.
I have not tested slp.
Best regards

Alain Barraud

when i run sqp_trust I have an error at line 72 in saocrkargin
if isempty(options)
% optsao = optimset('fmincon','Display','iter');<====
it seems necessary to set first
optsao = optimset('fmincon');
and add the display option.
Furthermore I obrain
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in sao_trust/saoprog (line 651)
My problem has only bounds linear inequalities and run with fmincon.
It was also OK with an older release of your very interesting code.
Any suggestion
Best regards

John Floyd

Robert Canfield

MATLAB Coder supports C code generation, but it will not generate code for MATLAB internal functions, some of which are used in slp_trust, sqp. Hence, the MATLAB Coder will not produce complete executable code if you try it with slp_trust, sqp. On the other hand, you could use it to generate C code for the slp_trust, sqp functions with calls to MATLAB functions that could be replaced with C code equivalents.

trust_adapt is a feature in development and not intended for release, yet The hook is in the code for me to test it, but the function m-file is not in the distribution. None of the test cases should use it.

omkar waghmare

Does it support automatic C code generation ?

Danxu Zhang

Robert Canfield

Ali, thanks. Initialization of vold will be fixed in next version I upload.

Ali Aghaeifar

in 'sqp.m' in line No. 698 where:
status=('Lagrange Multipliers not finite'); v=vold; break
the variable 'vold' is not defined before and can result in an error

Ali Aghaeifar

The function 'trust_adapt' in trust_region.m is undefined and causes an error

Hieu Nguyen

mohammad haghnejat

Can any one help me on this?
I don't know how to use this.

Thanks in advanced


It would be great if line search could recover from nan or inf values

Blake Van Winkle

In trying to run "runfHaftka4p2p1.m", I was unable to do so because 'trust_adapt' was not available for use in "slp_trust". Could you please include it? Thanks,


Sorry.. I've seen the example with the dummy constraint, nice job


very good for bounded constrained optimizations, but is it possible to perform bounded unconstrained optimization?

Payal Thukral

Hi Robert. Really great job !
Can you tell me if The SLP_Trust can be used for nonlinear equality constraints? I am trying to use it. Thanks!!

Robert Canfield

Inequality constraints are supported. Equality constraints are supported in sqp, but not in sip_trust. The user returns both in the same vector for sqp. See documentation on how to specify them.


Hi Robert, Thank you for sharing such an interesting code. One quick question. Do you maybe have an updated version that supports inequality constraints? Thank you very much.

Lionel Juillen AF

Robert Canfield

By default slp_trust and sqp request gradients of all constraints from the user, which should handle hundreds of constraints, but may falter for more than that (depending partly on number of design variables). A user may code gradient functions to take advantage of an active set strategy, which is implemented differently in the two codes. For slp_trust the user may code his gradient function to compute only active constraint gradients based on an optional input argument. Only the first iteration requires all gradients. For sqp the user may code her gradient function to compute only active constraint gradients based on a global variable, ACTIVE_CONSTRAINTS. The documentation in the help folder provides the details.


Hi Robert ,Thanks for your share. Does the toolbox can solve the large-scale NLP problem,which means it has hundreds of constrains?

Robert Canfield

Marco, the basic trust region strategy is classical (e.g., Moré, J.J. and D.C. Sorensen, "Computing a Trust Region Step," SIAM Journal on Scientific and Statistical Computing, Vol. 3, pp 553–572, 1983); however, the detailed implementation, including how to treat constraints, is original.


Hi Robert, I am also tryng to find a reference for the slp_trust algorithm you implemented. I am particulary interested in the trust region update phase, can you help me out? I have serched extensively on scholar but I do not found anything.

Robert Canfield

Marco, thank you. Yes, you did catch a typo: gradg should be gradf on that line. I will correct with next upload.


Hi Robert,
at line 290 of slp_trust is really

or it should be
gradf=gradf(:)' ?

Thank you for sharing this good piece of code!

Robert Canfield

slp_trust requires lp and sqp requires qp from optimization toolbox to solve respective search direction sub-problems.

Marc Matten

Okay, then I mixed up some downloads.
I had a look on your scipts, aswell. Is it possible to use them without the optimization toolbox?

Robert Canfield

Marc, not sure what you mean about modQPM.m (not one of my m-files). This implementation handles nonlinear and equality constraints.

Marc Matten

Hi Robert,
I really like your SQP program. I found that the current version of 'modSQP.m' handles only inequality and bound constraints. Is there an updated version or a simple way to respect equality and nonlinear constraints?

MATLAB Release Compatibility
Created with R2019b
Compatible with R2014b to R2019b
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!