function u = findbestu( x0, b, var_b0, var_w )
% x0 is first state
% b: nominal estimate of b remains the same throughout
% var_b0: initial b parameter variance
% var_w: variance of process noise

% x(k+1) = x(k) + b(k)*u(k) + w
% b(k+1) = b(k)
% w is zero mean noise with variance var_w

% u0 is first action
% c = cost( u0, x0, b, var_b0 )

N = 1001;
u0s(N) = 0;
cs(N) = 0;

u_best = 0;
c_best = 1e30;

for i = 1:N
 u0 = 10*(i-1)/(N-1);
 c = cost( u0, x0, b, var_b0, var_w );
 if ( c < c_best )
  u_best = u0;
  c_best = c;
 end
 u0s(i) = u0;
 cs(i) = c;
end

u = u_best;
