% eda04_07
% reads in noisy, linear data from file
% and computes and plots prediction error for a particular
% choice of intercept and slope, m1 and m2

% model estimate
M=2;
mest=[1.1, 2.3]';

% excel 1+2*x+0.5*(rand()-1)
T = load('linedata01.txt');

% now independently name the two columns of data
x = T(:,1);
dobs = T(:,2);
N = length(dobs);

% plot data as black circles
figure(1);
clf;
set(gca,'LineWidth',2);
hold on;
axis([-6 6 -15 15]);
plot(x,dobs,'ko','LineWidth',2);
xlabel('x');
ylabel('d');
title( 'plot of linedata01.txt' );

% data kerner
G=zeros(N,M);
G(:,1)=1;
G(:,2)=x;

% compute and plot predicted data
dpre = G*mest;
plot(x,dpre,'k-','LineWidth',2);

% compute and plot error
e=dobs-dpre;
for i = [1:N]
    y1 = dobs(i);
    y2 = dobs(i)-e(i);
    plot( [x(i), x(i)], [y1, y2], 'k:' ,'LineWidth',2 );
end

% colpute total error
E = e'*e;

E







