To solve this problem using MATLAB, we first define the function f(x) and its gradient and Hessian at any point x as follows:
f = @(x) 10*(x(2) - x(1)^2)^2 + (1-x(1))^2;
gradf = @(x) [-40*x(1)*(x(2)-x(1)^2) - 2*(1-x(1)); 20*(x(2)-x(1)^2)];
hessf = @(x) [-40*(x(2)-3*x(1)^2)+2, -40*x(1); -40*x(1), 20];
Then, we can define the quadratic model mk(p) as follows:
mk = @(x,p) f(x) + gradf(x)'*p + 0.5*p'*hessf(x)*p;
We can then plot the contour lines of mk(p) centered at x=[0−1]T as follows:
[X,Y] = meshgrid(-2:0.1:2);
Z = zeros(size(X));
x = [0; -1];
for i = 1:size(X,1)
for j = 1:size(X,2)
p = [X(i,j); Y(i,j)];
Z(i,j) = mk(x, p);
end
end
contour(X,Y,Z)
hold on
plot(x(1),x(2),'r.','MarkerSize',20)
This results in the following plot:
[image: Contour lines at x=[0;-1]] open
We can similarly plot the contour lines at a=[00.5]T as follows:
[X,Y] = meshgrid(-2:0.1:2);
Z = zeros(size(X));
x = [0; 0.5];
for i = 1:size(X,1)
for j = 1:size(X,2)
p = [X(i,j); Y(i,j)];
Z(i,j) = mk(x, p);
end
end
contour(X,Y,Z)
hold on
plot(x(1),x(2),'r.','MarkerSize',20)
This results in the following plot:
[image: Contour lines at x=[0;0.5]] open
To draw the family of solutions of minpmk(p) subject to ∥p∥≤, we can use the function in MATLAB. We start by defining the constraints on and an initial guess for :
lb = [-2;-2]; % lower bounds on p
ub = [2;2]; % upper bounds on p
Delta = 0.5; % trust region radius
x = [0;-1]; % center of trust region
p0 = [0.5;0.5]; % initial guess for p
Then, we can use fmincon to solve for the minimum of mk(p) subject to the trust region constraint:
options = optimoptions('fmincon','Display','none');
[p, ~, exitflag] = fmincon(@(p) mk(x,p), p0, [], [], [], [], lb, ub, @(p) norm(p)-Delta, options);
We can repeat this for different values of Δ to visualize how the solution changes as the trust region radius varies:
figure
[X,Y] = meshgrid(-2:0.1:2);
Z = zeros(size(X));
x = [0;-1];
for Delta = 0:0.25:2
for i = 1:size(X,1)
for j = 1:size(X,2)
p = [X(i,j); Y(i,j)];
Z(i,j) = mk(x, p);
end
end
contour(X,Y,Z);
hold on
plot(x(1),x(2),'r.','MarkerSize',20)
[p, ~, exitflag] = fmincon(@(p) mk(x,p), p0, [], [], [], [], lb, ub, @(p) norm(p)-Delta, options);
if exitflag > 0
plot(p(1),p(2),'g.','MarkerSize',20)
end
end
This results in the following plot:
[image: Family of solutions for different trust region radii at x=[0;-1]] open
We can similarly plot the family of solutions at a=[00.5]T:
figure
[X,Y] = meshgrid(-2:0.1:2);
Z = zeros(size(X));
x = [0;0.5];
for Delta = 0:0.25:2
for i = 1:size(X,1)
for j = 1:size(X,2)
p = [X(i,j); Y(i,j)];
Z(i,j) = mk(x, p);
end
end
contour(X,Y,Z);
hold on
plot(x(1),x(2),'r.','MarkerSize',20)
[p, ~, exitflag] = fmincon(@(p) mk(x,p), p0, [], [], [], [], lb, ub, @(p) norm(p)-Delta, options);
if exitflag > 0
plot(p(1),p(2),'g.','MarkerSize',20)
end
end
This results in the following plot:
[image: Family of solutions for different trust region radii at x=[0;0.5]] open
Note that the green dot represents the solution found by fmincon for each trust region radius. If exitflag is negative, it means that fmincon was unable to find a feasible solution within the trust region constraint.