function [Y,t] = update_Yt_adm_bd(n,lb,ub,X,Y,P,beta,t,tol)

% parameters
tol = min(1e-6,tol);
sigma = 1e-4;
k = 10;
f = -inf*ones(k,1);

A = X + P/beta;

fval = fval_cond_bd(A,lb,ub,t);
grad = grad_cond_bd(n,A,lb,ub,t);
f(1) = fval;
fmax = max(f);
step_init = 1;
iter = 1;

while 1
  
  dtest = max(t - grad,0) - t;
  if abs(dtest)/max(1,fval) < tol
    break
  end
  
  d = max(t - step_init*grad,0) - t;
  Delta = grad*d;
  
  stepsize = 1;
  tnew = t + stepsize*d;
  fval = fval_cond_bd(A,lb,ub,tnew);
  while fval > fmax + stepsize*sigma*Delta && stepsize > 1e-10 % Armijo rule
    stepsize = stepsize/2;
    tnew = t + stepsize*d;
    fval = fval_cond_bd(A,lb,ub,tnew);
  end
  
  if stepsize <= 1e-10
    break
  end
  
  gradnew = grad_cond_bd(n,A,lb,ub,tnew);
  dt = tnew - t;
  dg = gradnew - grad;
  step_init = min(max(dt^2/(dt*dg),1e-8),1);
  
  grad = gradnew;
  t = tnew;
  f(mod(iter,k) + 1) = fval;
  fmax = max(f);
  
%   fprintf(' iter, fval = %g, %g\n', iter, fval)
%   pause
  iter = iter + 1;
  
end

Y = min(max(A,lb*t),ub*t);