% olinjsin,  ickelinjär modellfunktion, Newtons metod
  clear, clf
  t=[0.5  1  1.5  2]';  y=[0.3 0.5 1.4 0.5]'; 
  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;   dcnorm=1;
  while dcnorm>0.5e-5 & iter<10
    u=w*(t-t0);  f=a+b*sin(u) - y;
    J=[ones(4,1) sin(u) b*(t-t0).*cos(u) -w*b*cos(u)];
    if iter==1, J, end           % skriv ut första jacobianen
    dc=-J\f;  dcnorm=norm(dc,inf)
    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)')



