function [fval, exitflag, output, x] = runqpbox4
% RUNQPBOX4 demonstrates 'HessMult' option for QUADPROG with bounds.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.3 $  $Date: 2000/08/30 02:03:42 $

load qpbox4 % Get xstart, u, l, B, A, f
mtxmpy = @qpbox4mult; % function handle to qpbox4mult subfunction

% Choose the HessMult option
% Override the TolPCG option
options = optimset('HessMult',mtxmpy,'TolPcg',0.01); 

% Pass B to qpbox4mult via the H argument. Also, B will be used in
% computing a preconditioner for PCG.
% A is passed as an additional argument after 'options'
[x, fval, exitflag, output] = quadprog(B,f,[],[],[],[],l,u,xstart,options,A);

%----------------------------------------------------------------------------
function W = qpbox4mult(B,Y,A);
%QPBOX4MULT Hessian matrix product with dense structured Hessian.
%   W = qpbox4mult(B,Y,A) computes W = (B + A*A')*Y where 
%   INPUT:
%       B - sparse square matrix (512 by 512)
%       Y - vector (or matrix) to be multiplied by B + A'*A.
%       A - sparse matrix with 512 rows and 10 columns.
%
%   OUTPUT:
%       W - The product (B + A*A')*Y.
%
  
% Order multiplies to avoid forming A*A',
%   which is large and dense
W = B*Y + A*(A'*Y);