%ln(u) , zl = z0 ,      LAB1
hold off;clear all;

U=[2.99, 2.81, 2.59, 2.3, 2.28, 2.21, 2.13, 1.87, 1.73, 1.64, ... 
1.66, 1.52, 1.39, 1.22, 1.24, 1.26, 1.2, 0.96, 0.86, 0.91];

n=0:19; 

scatter(n, U,'kx')

%We need U & n to be COLUMN vectors for fit() to work. Transposition.
Ut = U';
nt = n';
fittedcurve = fit( nt, Ut, 'exp1');
plot( fittedcurve, nt, Ut )

hold on
grid on

lnU=log(U);
scatter(n, lnU,'kx')

% "Least-squares" line. Aka line of best fit.
% !!! Unimplemented in Octave, use polyfit()
p = polyfit(n, lnU, 1);

%lobf = line of best fit
%using the coefficients stored in 'p'.
lobf=p(1).*n+p(2);
plot(n, lobf, 'm-')

str=['alpha: ', num2str(-p(1))];
title(str)

xlabel('Position')
ylabel('Amplitud')
legend('U', 'Anpassad kurva till U', 'ln(U)', 'Anpassad linje till ln(U)')