p=@(t) [7*cos(t);4*sin(t)];%one curve p(t) dp=@(t) [-7*sin(t);4*cos(t)];%p'(t) q=@(s) [cos(s)-2;2*sin(s)-1];%another curve q(s) dq=@(s) [-sin(s);2*cos(s)];%q'(t) r=@(x) p(x(1))-q(x(2));%vector conecting p(t) and q(t) dr=@(x) [dp(x(1)),-dq(x(2))];%Jacobian of r F=@(x) r(x)'*r(x);%the distance (squared) between the two points gradF=@(x) 2*dr(x)'*r(x); x0=[3.5;2.7];%initial point n=200; X=gradientmethod(gradF,0.01,x0,n); figure(1) clf hold on picture(p,q,x0) for i=100:100 picture(p,q,X(:,i)) end axis equal sqrt(F(x0)) figure(2) clf hold on graphF(F) plot(X(1,:),X(2,:),'rx')