%Interpolerande sinuskurva, NAM 6.9.2
%Bestäm a,b,w,t0 i F(t)=a+bsin(w(t-t0))
t=[0.5 1 1.5 2]';y=[0.3 0.5 1.4 0.5]';
a=0.7;b=0.7;w=pi;t0=1.2;c=[a b w t0]';
h=1;
while h>1e-4
    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)];
    delc=-J\f;h=norm(delc,inf);
    c=c+delc
    a=c(1);b=c(2);w=c(3);t0=c(4);
end
tt=[0:0.05:3]';Ftt=a+b*sin(w*(tt-t0));
plot(t,y,'o',tt,Ftt)

