%EXS 425
t=[ 0.8 1.7 2.5 3.3 4.1]';
y=[0.12 -0.09 0.06 -0.05 0.032]';
a=-0.17;

%startv�rde
w=(2*pi)/(t(3)-t(1));
b=(w/(2*pi))*(log(y(1))-log(y(3)));
x=[b w]';
iter=0;
%norm(x)
dx=x;
F=[0 0]';
%dxold=dx;
%while norm(dx)>1e-16
for i=1:15
    %dxold=dx;
    Y=a*exp(-b*t).*(cos(w*t)+(b/w)*sin(w*t))-y; 
    F1=-a*exp(-b*t).*(cos(w*t)+(b/w)*sin(w*t)).*t+a*exp(-b*t).*((1/w)*sin(w*t));
    F2=a*exp(-b*t).*(-sin(w*t).*t+(b/w)*cos(w*t).*t-(b/w^2)*sin(w*t));  
    F=[F1 F2];
    dx=-F\Y;%MKM!!!
    x=x+dx;
    b=x(1);
    w=x(2);
    
end
w
b
T=0:0.01:5;
Y=a*exp(-b*T).*(cos(w*T)+(b\w)*sin(w*T));
plot(T,Y,t,y,'o')
   
% Ynorm=0.006378712712758
% w =3.772122560556820
% b = 0.390312294811884
