t = [0 .3 .8 1.1 1.6 2.3]';
y = [0.5 0.82 1.14 1.25 1.35 1.40]';
plot(t,y,'o', 'linewidth', 3), grid on

%%
X = [ones(size(t)) t t.^2]
a = X\y
T = [0:0.1:2.5]';
Y = [ones(size(T)) T T.^2]*a;
plot(T, Y, '-', t,y,'o', 'linewidth', 3), grid on

%%
X = [ones(size(t)) exp(-t) t.*exp(-t)];
a = X\y
T = (0:0.1:2.5)';
Y = [ones(size(T)) exp(-T) T.*exp(-T)]*a;
plot(T, Y, '-', t,y,'o', 'linewidth', 3), grid on

%%
polyfit(t,y,2)

%%
p = [1 0 -2 -5];
r = roots(p)
p2 = poly(r)
g = [1 1 1 1 1]
polyder(g)

%%
x = [0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];
y = [-.447 1.978 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.2];
plot(x,y,'o',x,y, 'linewidth', 3);
%load data1.asc

%%
n = 2;
p = polyfit(x,y,n)

%%
xi = linspace(0,1,100);
yi = polyval(p,xi);
plot(x,y,'o',x,y,xi,yi,'--', 'linewidth', 3);

%%
pp = polyfit(x,y,10);
format short e
pp'
zi = polyval(pp,xi);
plot(x,y,'o',xi,yi,'--',xi,zi, 'linewidth', 3);

%%
x = 0:0.25:6;
%y = 2+6*x.^2-x.^3;
y = -x.^3 + 0*x.^2 + 6*x.^2 + 2;
y = y + randn(size(x));
p = polyfit(x,y,3)
xi = 0:0.02:6;
yi = polyval(p,xi);
plot(x,y,'o', xi,yi, 'linewidth', 3)


%%
x   = 0:.25:4;
y   = exp(x);
p2  = polyfit(x,y,2)
xi  = 0:0.02:4;
yi2 = polyval(p2,xi);
plot(x,y,'o', xi,yi2, 'linewidth', 3)
% $$$ hold on
% $$$ yi3 = polyval(p3,xi);
% $$$ plot(x,y,'o', xi,yi3, 'linewidth', 3)
% $$$ hold off
