% OBJECTIVE FUNCTION
A1 = 0.5*sin(1) - 2*cos(1) + sin(2)   - 1.5*cos(2)
A2 = 1.5*sin(1) - cos(1)   + 2*sin(2) - 0.5*cos(2)
f  = @(x) [ 1 + (A1 - (0.5*sin(x(:,1)) - 2*cos(x(:,1)) + sin(x(:,2)) - 1.5*cos(x(:,2)))).^2 + (A2 - (1.5*sin(x(:,1)) - cos(x(:,1)) + 2*sin(x(:,2)) - 0.5*cos(x(:,2)))).^2, (x(:,1) + 3).^2 + (x(:,2) + 1).^2]

% OPTIMIZATION SETTINGS
o = struct	% initializing struct
o.d = 2	% dimension of decision variable
o.lb = -pi	% lower bounds
o.ub = pi	% upper bounds

% ALGORITHM OPTIONS

o.maxit = 40	% number of iterations 
o.pop = 100	% number of population 

% OPTIMIZATION 
rng(0)	% for tractability 
[popPos,popFront,popCost,popInfo,traceIt] = nsga2(f,o)	% running minimization  

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% [~,~,~,~,~,info] = nsga2(f,o)
% info.plot = 'pareto'
% info.animate = true	% plot animation 
% info.animfreq = 4	% frame frequency 
% optimview('nsga2',info)