%
% Example macro about fitting a polynomial to 2D-data.
% TK 14.11.02
%
clear;
x = linspace(0,2,15);
e = 1; randn('state',0); y = x + e*(rand(size(x))-0.5);
%
a = plot(x,y,'bx','MarkerSize',14); axis([-0.1 2.1 -0.5 2.5]);
set(gca,'XTick',[0 0.5 1 1.5 2]);
deg = 1; p = polyfit(x,y,deg); y1 = polyval(p,x);
hold on
l = plot(x,y1,'g-'); set(l,'LineWidth',2)
hold off
%print -deps linaprox.eps
%
figure
a = plot(x,y,'bx','MarkerSize',14); axis([-0.1 2.1 -0.5 2.5]);
set(gca,'XTick',[0 0.5 1 1.5 2]);
deg = 5; p = polyfit(x,y,deg); y2 = polyval(p,x);
hold on
l = plot(x,y2,'g-'); set(l,'LineWidth',2)
hold off
%print -deps hoaprox.eps
