design example 1

Contents

setup

% define system
global cv th rn;
cv = [ 0 0.25 -0.15 0];
th = [ 0  0    0  0];
rn = [ 1 1.5 1 1 ];
% contours
n=128;
u1 = linspace(-0.1,0.3,n);
u2 = linspace(-0.2,0.2,n);
map = zeros(n,n);
map1 = map;
map2 = map;
for r=1:n
    v(2)=u2(r);
    for c=1:n
        v(1)=u1(c);
        f = sing1(v);
        map(r,c)=f'*f;
        map1(r,c)=f(1);
        map2(r,c)=f(2);
    end
end
cmax = max(max(map));
fprintf('contour map max %g min %g\n',cmax,min(min(map)));
map = map/cmax;
contour map max 0.0409766 min 1.8191e-009
% resize plot window
pos = get(gcf,'Position');
pos(3)=480;
pos(4)=480;
set(gcf,'Position',pos);

zeros of merit function

% show zero values of merit function
contour(u1,u2,map2,[0 0],'b');
axis square;
hold on;
contour(u1,u2,map1,[0 0],'k');
hold off;
xlabel('cv1');
ylabel('cv2');

contours

[c2 hc2] = contour(u1,u2,map,logspace(1,-4,16));
nc = get(hc2,'Children');
for i = 1:4:length(nc)
   set(nc(i),'LineWidth',1.5);
end
axis square;
legend;
xlabel('cv1');
ylabel('cv2');

optimization

% initial values
x = [ 0.25 -0.15]';
% iterate twice
pos = zeros(3,2);
pos(1,:)=x;
for k=1:2
	fprintf('step %d\n',k);
	[A fz] = calculate_derivatives(@sing1,x)
    fprintf('merit function: %g\n',norm(fz));
   s = -A\fz
   x = x + s
   pos(k+1,:)=x;
end
step 1

A =

    0.5000   -0.5000
   -0.0292    0.1958


fz =

    0.1500
   -0.0183

merit function: 0.151116

s =

   -0.2425
    0.0575


x =

    0.0075
   -0.0925

step 2

A =

    0.5000   -0.5000
   -0.0302    0.0719


fz =

    0.0000
   -0.0034

merit function: 0.0034375

s =

    0.0825
    0.0825


x =

    0.0900
   -0.0100

hold on
plot(pos(:,1),pos(:,2),'ko-','LineWidth',2);
hold off

SVD

% SVD
v = [0.25 -0.15]';
[A fz] = calculate_derivatives(@sing1,v);
[U,S,V] = svd(A,0)
U =

   -0.9743    0.2252
    0.2252    0.9743


S =

    0.7253         0
         0    0.1149


V =

   -0.6808    0.7325
    0.7325    0.6808

% test SVD
disp('A');
disp(A);
% should be A
disp('U*S*V''');
disp(U*S*V')
% should be identity matrix
disp('U''*U');
disp(U'*U)
% should be identity matrix
disp('V''*V');
disp(V'*V);
A
    0.5000   -0.5000
   -0.0292    0.1958

U*S*V'
    0.5000   -0.5000
   -0.0292    0.1958

U'*U
    1.0000   -0.0000
   -0.0000    1.0000

V'*V
    1.0000         0
         0    1.0000