close all
clear all
clc

% load resistor_data_1
load resistor_data_2

N=length(i)

figure, hold on
% plot(i,Vtrue)
plot(i,V,'ok')

% Sample mean estimate
R_N=mean(V./i)
V_N=R_N*i;
plot(i,V_N,'g')

% Least-squares estimate
% R_LS=inv(i'*i)*i'*V
R_LS=i\V
V_LS=R_LS*i;
plot(i,R_LS*i,'c')

% Gauss-Markov estimate
st=5;
Seta=st^2*eye(N);
R_GM=inv(i'*inv(Seta)*i)*i'*inv(Seta)*V
plot(i,R_GM*i,'r')

% Bayesian estimate
R_m=3;
Srr=0.01;
st=5;
Seta=st^2*eye(N);
Seta(7,7)=Seta(7,7)*2; % accounting for anomalies in datum 7 (resistor_data_2)
Srv=Srr*i';
Svv=Srr*i*i'+Seta;
R_B=R_m+Srv*(Svv^-1)*(V-R_m*i)
plot(i,R_B*i,'b')
