def water_filling(n, a, sum_x=1):
 x = cvx.Variable(n)
 alpha = cvx.Parameter(n, sign='positive')
 alpha.value = a
 obj = cvx.Maximize(cvx.sum_entries(cvx.log((alpha + x))))
 constraints = [(x >= 0), ((cvx.sum_entries(x) - sum_x) == 0)]
 prob = cvx.Problem(obj, constraints)
 prob.solve()
 if (prob.status == 'optimal'):
  return (prob.status, prob.value, x.value)
 else:
  return (prob.status, np.nan, np.nan)

def water_filling ( n , a , sum_x = 1 ) : x = cvx . Variable ( n ) alpha = cvx . Parameter ( n , sign = 'positive' ) alpha . value = a obj = cvx . Maximize ( cvx . sum_entries ( cvx . log ( ( alpha + x ) ) ) ) constraints = [ ( x >= 0 ) , ( ( cvx . sum_entries ( x ) - sum_x ) == 0 ) ] prob = cvx . Problem ( obj , constraints ) prob . solve ( ) if ( prob . status == 'optimal' ) : return ( prob . status , prob . value , x . value ) else : return ( prob . status , np . nan , np . nan )
boyd and vandenberghe .