function [eta_trj,Q] = optimize_Trajectory_M_2_Using_MATLAB_Solver(A,Qr,P,N,K,M,sigma2,rho,H,w,Smax,dmin)
%UNTITLED10 Summary of this function goes here
%   Detailed explanation goes here

%% MATLAB fmincon solver
for n = 1:N 
    % Q initialization 
    x0(n,1:2,1) = Qr(n,:,1) ;  
    x0(n,1:2,2) = Qr(n,:,2) ; 
    % Slack variable intialization 
    for k = 1 : K 
        x0(n,k+2,1) = norm(Qr(n,:,1) - w(k,:),2)^2 ; 
        x0(n,k+2,2) = norm(Qr(n,:,2) - w(k,:),2)^2 ; 
    end 
end 

% x0  = Qr ; 
problem = createOptimProblem('fmincon','objective',...
        @(x) -min( rate_conve_trajectory_for_MATLAB_Solver(x,A,Qr,P,N,K,M,sigma2,rho,H,w)),...
                             'nonlcon',@(x) constraints_for_MATLAB(x,Qr,dmin,Smax,M,N,K,w),'x0',x0) ; 
% gs = GlobalSearch('FunctionTolerance',1e-4);                         
%[Q  , eta_trj]         =run(gs,problem) ;                
[Q  , eta_trj]   = fmincon(problem)  ;
eta_trj =  -1*eta_trj; 
end

