dx1 SVD and gradient
Contents
load sing1
draw contours
[c2 hc2] = contour(u1,u2,map,logspace(1,-4,16));
axis square;
legend;
xlabel('cv1');
ylabel('cv2');
x = [ 0.25 -0.15]';
[A fz] = calculate_derivatives(@sing1,x);
gradient
g = A'*fz;
disp('gradient');
disp(g);
g = g/norm(g);
hold on
s = -0.05;
plot(x(1) + [0 s*g(1)],x(2) + [0 s*g(2)],'go-','LineWidth',2);
hold off
gradient
0.0755
-0.0786
xs = -A\fz;
disp('LSQD xs');
disp(xs);
LSQD xs
-0.2425
0.0575
SVD
[U S V] = svd(A,0);
disp(S)
0.7253 0
0 0.1149
SVD ellipse
w = diag(S);
wmin = min(w);
w = wmin./w;
disp(w);
w = 0.05*w;
theta = linspace(0,1,50)*2*pi;
p = [w(1)*cos(theta)' w(2)*sin(theta)'];
p = V*p';
hold on;
plot(p(1,:)+x(1),p(2,:)+x(2),'b--','LineWidth',2);
hold off;
0.1584
1.0000
solution vector
w = diag(S);
xnew = V'*x;
fnew = U'*fz;
disp('fnew');
disp(fnew);
xs = V*(-fnew./w);
disp('SVD xs');
disp(xs);
g = V*(w.*fnew);
disp('SVD gradient');
disp(g);
hold on
plot(x(1)+[0 xs(1)],x(2)+[0 xs(2)],'ro-','LineWidth',2);
hold off;
fnew
-0.1503
0.0159
SVD xs
-0.2425
0.0575
SVD gradient
0.0755
-0.0786
draw contours again
[c2 hc2] = contour(u1,u2,map,logspace(1,-4,16));
axis square;
legend;
xlabel('cv1');
ylabel('cv2');
test svd_diagram
x = [ 0.25 -0.15]';
for k=1:2
[A fz] = calculate_derivatives(@sing1,x);
x = svd_diagram(A,fz,x,0.05);
end