%
%
function [f1,f2]=bobs_fop0_b(u,s,t,flg);
%
%  s = [x1 x2 q]'
%
  A = [1 -2; 1 0]; B=[0;-2];
  rr = 1;
  Sf = 1; R = 1; Q = 1;
%
x1 = s(1); x2 = s(2); q = s(3);
x = [x1; x2];
%
if flg == 1
   f1 = [A*x+B*u; 0.5*R*(x1-rr)^2+0.5*Q*u^2];  
elseif flg == 2
   f1 = 0.5*Sf*(x1-rr)^2 + q; f2 = [Sf*(x1-rr) 0 1];
elseif flg == 3
    f1 = [A zeros(2,1) ; R*(x1-rr) 0 0];
    f2 = [B; Q*u];
end;