function Z = sampleq(x,y,H,b,c); % Z = sampleq(x,y,H,b,c) % Makes a 2-D table of values of % the quadratic function of 2 variables % % z = (1/2)v'*H*v-b'*v+c, v=[x;y] % % using outer products. % % H is 2x2 symmetric % b is 2x1 % c is 1x1 % x = x(:)'; % row vector: 'horizontal' coordinate y = y(:); % col vector: 'vertical' coordinate rw = ones(size(x)); cl = ones(size(y)); Z = 0.5*(H(1,1)*cl*x.^2 + ... 2*H(1,2)*y*x + ... H(2,2)*y.^2*rw) - ... b(1)*cl*x - b(2)*y*rw + c*cl*rw;