% ellipsmod,  Ellipsanpassning
  clear, clf
  x=[1 7 10 17  5 12 14]';  
  y=[6 4 12  7 11  3  4]';  
  subplot(2,2,1), plot(x,y,'o'), axis equal
  title('Sju givna punkter'), drawnow
  xc=10;  yc=8;  a=8;  b=3;                  % startgissn. ur figuren          
  p=[xc yc a b]';  iter=0; 
  disp('    norm(f)')
  while iter<5
    xd=x-xc;  yd=y-yc;
    f=xd.^2/a^2+yd.^2/b^2-1;  disp(norm(f))  % skriv ut norm(f)
    J=-2*[xd/a^2  yd/b^2  xd.^2/a^3  yd.^2/b^3];
    dp=-J\f; 
    p=p+dp;  iter=iter+1;
    xc=p(1); yc=p(2); a=p(3); b=p(4);
  end
  a,b,xc,yc
  dv=2*pi/60; v=dv*(0:60); 
  subplot(2,2,2), plot(x,y,'o', xc+a*cos(v),yc+b*sin(v)), axis equal
  title('Bäst anpassande ellips')





