function optimization(method)

% optimization(method)
%   solves a shape optimization problem
%   governed by 2-dimensional linear magnetostatics
%   by the sequential quadratic programming method with BFGS
%   update of the Hessian matrix while using either numerical
%   differentiation (method=='n') or the adjoint method
%   (method=='a')

% number of design variables
numDes = 4;

% initial design
p0 = zeros(numDes,1);
visualize(p0);

% box constraints
pl = -0.02*ones(numDes,1);
pu = 0.01*ones(numDes,1);

if method=='n'
  % numerical differentiation
  popt = constr('costFunc',p0,[],pl,pu);
  visualize(popt);
elseif method=='a'
  % adjoint method
  popt = constr('costFunc',p0,[],pl,pu,'gradCostFunc');
  visualize(popt);
end

