%% Goal Attainment with Bounds
% The objective function is
% F(x) = \left [ {
% {2 + \|x-p_1\|^2}
% \atop
% {5 + \|x-p_2\|^2/4} }\right ].
% Here, p_1 = [2,3] and p_2 = [4,1]. The goal is [3,6], the weight is [1,1], and the bounds are 0\le x_1\le 3, 2\le x_2\le 5.
% Create the objective function, goal, and weight.

p_1 = [2,3];
p_2 = [4,1];
fun = @(x)[2 + norm(x-p_1)^2;5 + norm(x-p_2)^2/4];
goal = [3,6];
weight = [1,1];

% Create the bounds.

lb = [0,2];
ub = [3,5];

% Set the initial point to [1,4] and solve the goal attainment problem.

x0 = [1,4];
A = []; % no linear constraints
b = [];
Aeq = [];
beq = [];
x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub)

% Find the value of F(x) at the solution.

fun(x)

% fgoalattain more than meets the goals. Because the weights are equal, the solver overachieves each goal by the same amount.
% Copyright 2018 The MathWorks, Inc.