% olinj8sin, ickelinjär modellanpassning
  clear, clf
  n=8
  t=[0.5  0.8  1  1.2  1.5 1.8  2  2.4]';  
  y=[0.3  0.3 0.5 0.9  1.4 1.1 0.5 0.3]'; 
  subplot(1,2,1), stem(t,y), axis([0 3 0 1.6])
  title('Givna data'), grid, drawnow
  a=0.7;  b=0.7;  w=pi;  t0=1.2;
  c=[a b w t0]';        
  iter=0;   
  disp('    norm(f)')               
  while iter<5                 % pröva om fem iterationer räcker
    u=w*(t-t0); 
    f=a+b*sin(u) - y; 
    disp(norm(f));             % kolla att norm(f) avtar mot ett minimum
    J=[ones(n,1) sin(u) b*(t-t0).*cos(u) -w*b*cos(u)];
    dc=-J\f; 
    c=c+dc;  iter=iter+1; 
    a=c(1);  b=c(2);  w=c(3);  t0=c(4); 
  end, c, iter 
  tt=(0:0.05:3)'; Ft=a+b*sin(w*(tt-t0));  
  subplot(1,2,2), plot(t,y,'o',tt,Ft), axis([0 3 0 1.6])
  title('Modell:  F = a + b sinw(t-t0)')




