% cJ2x.m
%     Example of a 2-D performance index
%       3 March 2005
N = 3 ;
p = 2 ;
% X = rand(p,N); D = rand(1,N) ;
% q = round(64*(D*X')/N)
% R = round(32*(X*X')/N)
% c = round(32*(D*D')/N)
q = [5 4] ;
R = [9     4
     4    10 ];
c = 1 ;

wo = q/R
dw = -1.9:0.2:1.5 ;
[w1 w2] = meshgrid(wo(1)+dw, wo(2)+dw) ;

w = [w1(:) w2(:)] ;
JJ = zeros(1,size(w,1)) ;
for k = 1:size(w,1), JJ(k) = w(k,:)*R*w(k,:)' ; end
JJ = JJ - q*w' + c ;
J = zeros(size(w1)) ;
mx = 0.23*max(JJ) ;
JJ(find(JJ>mx)) = mx ;
J(:) = JJ/mx ;
figure(1)
% myfigA(1,10,9)
surfc(w1, w2, J) , grid on, xlabel('w1'), ylabel('w2'),
title('Performance Index:  J(w1, w2)'), drawnow
% print -f1 -deps2 cJ2x
