% Driver file for constrained optimisation with the quadratic-penalty method.
% Sets up the problem (objective function, constraints, etc.), then calls
% qpenalty and plots/tabulates results.

range = [-2 2;-1 3];			% Range to plot the functions

% Parameters for the functions
A1 = [-2 0.5;0.5 1]; b1 = [1;-0.3]; c1 = 0;
A2 = -eye(2); b2 = [0;0]; c2 = 0.25;
A3 = [0 0;0 0]; b3 = [1;-2]; c3 = 0;  

% Objective function and equality and inequality constraints
f = @quadf; paramf = {A1,b1,c1};
E = {@quadf}; paramE = {{A2,b2,c2}};
I = {@quadf}; paramI = {{A3,b3,c3}};

% Unconstrained optimisation method and its parameters.
% In paramO do not include x0, tol, maxit (they are set by qpenalty).
O = @newtoncg; paramO = {'linear'};
% $$$ O = @steepdesc; paramO = {};
% $$$ O = @prcg; paramO = {};
% $$$ O = @bfgs; paramO = {};

% Parameters for qpenalty
x0 = [1.5;2.4];				% Starting point for qpenalty
% $$$ x0 = [-1;-1];
mu0 = 1;				% Starting penalty parameter
tol = [];				% Convergence tolerance
maxit = 50;				% Maximum number of iterations

% Quadratic-penalty constrained optimisation
[X,LE,LI,F,CE,CI,MU,ERR,Oit,condH,G] = ...
    qpenalty(f,paramf,E,paramE,I,paramI,O,paramO,x0,mu0,tol,maxit);

% Plot sequence of iterates
fcontours(f,paramf,E,paramE,I,paramI,range,50); plotseq(X);

