Chapter 3 Graphical Optimization and Basic Concepts
MATLAB Code
%Create a grid from -1 to 7 with an increment of 0.01 for the variables x1 and x2
[x1,x2]=meshgrid(-1:0.01:7.0, -1:0.01:7.0);
%Enter functions for the minimization problem
f=(x1-3).^2+(x2-3).^2;
xlabel(‘x1’),ylabel(‘x2’) %Specifies labels for x– and y-axes
hold on %retains the current plot and axes properties for all subsequent plots
%Use the “contour” command to plot constraint/minimization functions
cv1=[0 0]; %Specifies two contour values
const1=contour(x1,x2,g1,cv1,’k’,’LineWidth’,3); %Plots two specified contours of g1; k=black color
text(0.25,4.5,’g1′) %Writes g1 at the location (0.25, 4.5)
cv11=[0.01:0.01:0.1];
const1=contour(x1,x2,g1,cv11,’c’);
text(0.5,0.75,’Feasible Region’)
fv=[2 6]; %Defines contours for the minimization function