function [rate_trj] = rate_convex_trajectory_M1(Q,A,Qr,P,N,K,sigma2,rho,H,w)
%UNTITLED11 Summary of this function goes here
%calculates the approximate rate underestimator for optimizing the
%trajectory
for k = 1:K 
    if isnumeric(Q)
        rate_trj(k) = 0 ; 
    else
        rate_trj(k) = cvx(0) ; 
    end
    for n = 1:N 
        A_const = (((P(n)*rho)/(H^2 + norm(Qr(n,:)-w(k,:),2)^2)^2) * log2(exp(1))) / ... 
                  (((P(n)*rho)/(H^2 + norm(Qr(n,:)-w(k,:),2)^2)) + sigma2) ; 
        B_const = log2( ((P(n)*rho)/(H^2 + (norm(Qr(n,:)-w(k,:),2))^2)) + sigma2) ; 
%         R_hat = -A_const * (2*(Q(n,:)-w(k,:))*(Qr(n,:)-w(k,:))') + B_const ; 
%       This is wrong since this will disable the convergance condition
%         R_hat = -A_const * (S(n,k) -(norm(Qr(n,:)-w(k,:),2))^2) ; 
        R_hat = -A_const * ( (sum_square(Q(n,:)-w(k,:))) -(norm(Qr(n,:)-w(k,:),2))^2) + B_const ;
        rate_trj(k) = rate_trj(k) + A(n,k,1) *  (R_hat - log2(sigma2)) ; 
       
    end
    rate_trj(k) = 1/N * rate_trj(k) ; 
end

