0% found this document useful (0 votes)
8 views9 pages

Assignment 1_checked

The document contains solutions to various optimization problems, including linear programming and quadratic programming using MATLAB. It discusses concepts such as the Hessian matrix, exact line search, and backtracking methods for optimization. The solutions include code snippets and outputs for different questions related to minimizing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views9 pages

Assignment 1_checked

The document contains solutions to various optimization problems, including linear programming and quadratic programming using MATLAB. It discusses concepts such as the Hessian matrix, exact line search, and backtracking methods for optimization. The solutions include code snippets and outputs for different questions related to minimizing functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

You can also check that the Hessian of J is

positive definite, so it's a convex function.


H<0 means negative definite, for which both eigenvalues are negative.
Here, H is sign indefinite.
4x2
Hessian of phi = Hessian of J + Hessian of P

Calculation error.
ASSIGNMENT 1
Name: Ashutosh Mishra
Roll No: 121EE0337

SOLUTION-4:
% Question 4
f = [-1; -1];
A = [1 2;
2 1;
-1 0];
b = [10; 10; 0];
Aeq = [0 1];
Beq = [3];

[x, fval] = linprog(f, A, b, Aeq, Beq);

fprintf("Final x1 = %0.4f, x2 = %0.4f",x(1), x(2));


fprintf("Minimized value of J(x1, x2) = %0.4f", fval);

SOLUTION-5:
% Question 5
H = [2 0;
0 2];
f = [-4;
-2];
A = [-1 -1;
-1 0];
b = [-4;
0];
[x, fval] = quadprog(H, f, A, b);
fprintf("Final x1 = %0.4f, x2 = %0.4f",x(1), x(2));
fprintf("Minimized value of J(x1, x2) = %0.4f", (fval+6));
SOLUTION-6:
For exact line search to find the value of alpha initial value were assumed as x0 and y0
−2𝑥0
∆X = −∇𝐽 = [ ]
−4𝑦0

𝐽(𝑋 + 𝛼∆X, Y + 𝛼∆Y ) = (x0 − 2x0 𝛼)2 + 2(𝑦0 − 4𝑦0 𝛼)2


Differentitating wrt 𝛼 and equating with zero to find the optimal value of 𝛼:
𝑑𝐽
= −4𝑥0 (𝑥0 − 2𝑥0 𝛼) − 16𝑦0 (𝑦0 − 4𝑦0 𝛼) = 0
𝑑𝛼
Solving the above equation we have

𝑥02 + 4𝑦02
𝛼=
2𝑥02 + 16𝑦02

% Question 6
% Exact Line Search
XY = [2; 1];
x = XY(1);
y = XY(2); There was an error in the question. I meant the 2-norm of grad(J) to be less than
JLimit = 0.0001; 10^-4 be the stopping criterion. Anyways it's fine whatever you did
% J(x, y) = x^2 + 2 * y^2;
with given information as the minimum value of function is zero.
J = 1;
counter = 1;

while(abs(J) > JLimit)


gradJ = [2*x;
4*y];
delXY = -gradJ;
alpha = (x^2 + 4 * y^2) / (2 * x^2 + 16 * y^2);

newXY = XY + alpha * delXY;


XY = newXY;
x = XY(1);
y = XY(2);
J = x^2 + 2 * y^2;
fprintf("Iteration-%d: alpha = %0.4f, X = %0.4f Y = %0.4f\n",...
counter, alpha, x, y);
counter = counter + 1;
end
fprintf("Total Number of Iterations: %d", (counter - 1));
fprintf("Final value of X = %0.4f, Y = %0.4f", XY(1), XY(2));
% Backtracking
XY = [2; 1];
JLimit = 0.0001;
beta = 0.25;
gamma = 0.5;
alpha = 1;
iterationLimit = 1000;
for i = 1:iterationLimit
J = (XY(1))^2 + 2 * (XY(2))^2;
gradJ = [2*XY(1);
4*XY(2)];
delXY = -gradJ;
newXY = XY + alpha * delXY;
newX = newXY(1);
newY = newXY(2);
newJ = newX^2 + 2 * newY^2;
fprintf("Iteration-%d: alpha = %0.4f, X = %0.4f Y = %0.4f\n",...
i, alpha, newXY(1), newXY(1));
if (newJ > J + beta * alpha * transpose(gradJ) * delXY)
alpha = gamma * alpha;
end
if (newJ < JLimit)
counter = i;
break;
end;
XY = newXY;
end
fprintf("Total Number of Iterations: %d", (counter - 1));
fprintf("Final value of X = %0.4f, Y = %0.4f", XY(1), XY(2));
SOLUTION-8:
% Question 8
mu1 = 0.1;
alpha = 0.1;
X = [1;
0.5];
gradJ = [-1;
-2];
n = 3;
for i = 1:n
x1 = X(1);
x2 = X(2);

h1 = x1*x1 + 2*x2*x2 - 2;
h2 = -x1;
h3 = -x2;
del2h1 = [2 0;
0 2];
gradh1 = [2*x1;
Same mistake.
2*x2];
gradh2 = [-1;
0];
gradh3 = [0;
-1];

A = mu1 * (-1/h1 * del2h1 +...


1/(h1 * h1) * gradh1 * transpose(gradh1) +...
1/(h2 * h2) * gradh2 * transpose(gradh2) +...
1/(h3 * h3) * gradh3 * transpose(gradh3));

b = -gradJ + mu1 * (1/h1 * gradh1 + 1/h2 * gradh2 + 1/h3 * gradh3);


delX = inv(A) * b;
newX = X + alpha * delX;
X = newX;
fprintf("Iteration %d\n", i);
fprintf("delX1 = %0.4f, delX2 = %0.4f, X1 = %0.4f, X2 = %0.4f\n",...
delX(1), delX(2), X(1), X(2));
end

You might also like