You are on page 1of 12

OPTIMAL CONTROL

ASSIGNMENT 03

MUHAMMAD MOHSIN KHAWAJA


MS-EE(EPC-3)
118339

Insight
As we are using Armijo line search to determine the value of step size we
will not get the exact value as we can get using the Exact line search
method. So, the value of the function obtained using step size from Armijo
line search never reach zero even after a lot of iterations the value of
function decreases until it becomes constant (Accumulation points) and
remain at that constant value.

PART (a) c=2


1.

Contour plot of the function with a plot of iterates


1
9

0.9
0.8
0.7
0.6
9

0.5
0.4
0.3
0.2
9

0.1

0.5

1.5

2.5

2.

Plot of the value of the function with respect to the iteration


number
10
9
8

Value of func

7
6
5
4
3
2
1
0

4
5
Iteration number

3.

MATLAB Code

clc
clear all
close all
%c = 2
% f=x.^2 + (y.^2)/c;
% df/dx=2*x;
% df/dy=y;
F=zeros(1,10);
X=[3,zeros(1,9)];
Y=[1,zeros(1,9)];
c=2;
x0=3;
y0=1;
a=1;
r=0.5;
sig=0.5;
for k=1:10
Df=[2*(X(k)) (Y(k))];
dk=[-2*(X(k)) ; -(Y(k))];
P= Df * dk;
P=r*a*P;
X(k+1)= X(k) - a*(X(k));
Y(k+1)= Y(k) - a*Y(k);
F(k)=X(k).^2 + (Y(k).^2)/c;
F(k+1)=X(k+1).^2 + (Y(k+1).^2)/c;
if(F(k+1) - F(k) <= P)
alpha=a;
for l=1:10
F(l)=X(l).^2 + (Y(l).^2)/c;
if( 2*(X(l))==0 && (Y(l))==0)
display('static value is')
display('X=')
display(X(l+1))
display('Y=')
display(Y(l+1))
else
if(l<10)
X(l+1)= X(l) - alpha*(X(l));
Y(l+1)= Y(l) - alpha*(Y(l));
end
end
end
[X1,Y1] = meshgrid(X,Y);
fx=X1.^2 + (Y1.^2)/2;
contour(X1,Y1,fx,'ShowText','on')
figure

K=0:9;
plot(K,F)
xlabel('Iteration number')
ylabel('Value of func')
break;
else
a=sig*a;
end
end

PART (a) c=10


1)

Contour plot of the function with a plot of iterates


1
9

0.9
0.8
0.7
0.6
9

0.5
0.4
0.3
0.2
9

0.1

0.5

1.5

2.5

2)

Plot of the value of the function with respect to the iteration


number
10
9
8

Value of func

7
6
5
4
3
2
1
0

3) Matlab code
clc
clear all
close all
%c = 10;
% f=x.^2 + (y.^2)/c;
% df/dx=2*x;
% df/dy=y/5;
F=zeros(1,10);
X=[3,zeros(1,9)];
Y=[1,zeros(1,9)];
% x0=3;
% y0=1;
c=10;
a=1;
r=0.5;
sig=0.5;
for k=1:10
Df=[2*(X(k)) (Y(k))/5];
dk=[-2*(X(k)) ; -(Y(k))/5];
P= Df * dk;
P=r*a*P;
X(k+1)= X(k) - a*(X(k));
Y(k+1)= Y(k) - a*Y(k);

4
5
Iteration number

F(k)=X(k).^2 + (Y(k).^2)/c;
F(k+1)=X(k+1).^2 + (Y(k+1).^2)/c;
if(F(k+1) - F(k) <= P)
alpha=a;
for l=1:10
F(l)=X(l).^2 + (Y(l).^2)/c;
if( 2*(X(l))==0 && (Y(l)/5)==0)
display('static value is')
display('X=')
display(X(l+1))
display('Y=')
display(Y(l+1))
else
if(l<10)
X(l+1)= X(l) - alpha*(X(l));
Y(l+1)= Y(l) - alpha*(Y(l));
end
end
end
[X1,Y1] = meshgrid(X,Y);
fx=X1.^2 + (Y1.^2)/2;
contour(X1,Y1,fx,'ShowText','on')
figure
K=0:9;
plot(K,F)
xlabel('Iteration number')
ylabel('Value of func')
break;
else
a=sig*a;
end
end

PART (a) c=100


3)

Contour plot of the function with a plot of iterates


1
9

0.9
0.8
0.7
0.6
9

0.5
0.4
0.3
0.2
9

0.1

0.5

1.5

2.5

4)

Plot of the value of the function with respect to the iteration


number
10
9
8

Value of func

7
6
5
4
3
2
1
0

3) Matlab code
clc
clear all
close all
%c = 100;
% f=x.^2 + (y.^2)/c;
% df/dx=2*x;
% df/dy=y/50;
F=zeros(1,10);
X=[3,zeros(1,9)];
Y=[1,zeros(1,9)];
% x0=3;
% y0=1;
c=100;
a=1;
r=0.5;
sig=0.5;
for k=1:10
Df=[2*(X(k)) (Y(k))/50];
dk=[-2*(X(k)) ; -(Y(k))/50];
P= Df * dk;
P=r*a*P;
X(k+1)= X(k) - a*(X(k));
Y(k+1)= Y(k) - a*Y(k);
F(k)=X(k).^2 + (Y(k).^2)/c;
F(k+1)=X(k+1).^2 + (Y(k+1).^2)/c;

4
5
Iteration number

if(F(k+1) - F(k) <= P)


alpha=a;
for l=1:10
F(l)=X(l).^2 + (Y(l).^2)/c;
if( 2*(X(l))==0 && (Y(l)/50)==0)
display('static value is')
display('X=')
display(X(l+1))
display('Y=')
display(Y(l+1))
else
if(l<10)
X(l+1)= X(l) - alpha*(X(l));
Y(l+1)= Y(l) - alpha*(Y(l));
end
end
end
[X1,Y1] = meshgrid(X,Y);
fx=X1.^2 + (Y1.^2)/2;
contour(X1,Y1,fx,'ShowText','on')
figure
K=0:9;
plot(K,F)
xlabel('Iteration number')
ylabel('Value of func')
break;
else
a=sig*a;
end
end

PART (b)
1. Plots of the value of the functions with respect to the iteration
number
10
9
8

Value of func

7
6
5
4
3
2
1
0

4
5
Iteration number

2. MATLAB code
clc
clear all
close all
% f=x.^2 + (y.^2)/10 + (z.^2)/100;
% df/dx=2*x;
% df/dy=y/5;
F=zeros(1,10);
X=[3,zeros(1,9)];
Y=[1,zeros(1,9)];
Z=[4,zeros(1,9)];
% x0=3;
% y0=1;
% z0=4;
a=1;
r=0.5;
sig=0.5;
for k=1:10
Df=[2*(X(k)) (Y(k))/5 (Z(k))/50];
dk=[-2*(X(k)) ; -(Y(k))/5 ; -(Z(k))/50];
P= Df * dk;
P=r*a*P;

X(k+1)= X(k) - a*(X(k));


Y(k+1)= Y(k) - a*Y(k);
Z(k+1)= Z(k) - a*Z(k);
F(k)=X(k).^2 + (Y(k).^2)/10 + (Z(k).^2)/100;
F(k+1)=X(k+1).^2 + (Y(k+1).^2)/10 + (Z(k+1).^2)/100;
if(F(k+1) - F(k) <= P)
alpha=a;
for l=1:10
F(l)=X(l).^2 + (Y(l).^2)/10 + (Z(k).^2)/100;
if( 2*(X(l))==0 && (Y(l))==0)
display('static value is')
display('X=')
display(X(l))
display('Y=')
display(Y(l))
display('Z=')
display(Z(l))
else
if(l<10)
X(l+1)= X(l) - alpha*(X(l));
Y(l+1)= Y(l) - alpha*(Y(l));
Z(l+1)= Z(l) - alpha*(Z(l));
end
end
end
K=0:9;
plot(K,F)
xlabel('Iteration number')
ylabel('Value of func')
break;
else
a=sig*a;
end
end

You might also like