% ee93wblf.m tlyeh 93,7,20, rev tly 93,7,22
iD=[2,10,22,33,40]'*1e-3; vD=[1.7,1.8,1.9,2.0,2.0]';
 A=[iD,ones(size(iD))];
 th=inv(A'*A)*(A'*vD); RD_on=th(1,1), VD_on=th(2,1), % (8.14ohm,1.706V),
figure(1)
hold off, plot(vD,iD,'x'),hold on, plot((RD_on*iD+VD_on*ones(size(iD))),iD)
 A4= [iD(1:4),ones(size(iD(1:4)))];
 th4=inv(A4'*A4)*(A4'*vD(1:4)); RD_on4=th4(1,1), VD_on4=th4(2,1), % (9.46ohm,1.69V)
 plot((RD_on4*iD+VD_on4*ones(size(iD))),iD,':')

% 2.c 
iD=[2,40]*1e-3; RFG=50;R=200;Vs= (RFG+R+RD_on)*iD+VD_on*ones(size(iD)),
% 2.d
vDt_Vdiv=0.5; vyt_Vdiv=2; R=202; vDtdiv=[3.4,3.6,3.85,4.12,4.3]'; vytdiv=[0.35,1,2,3,4]';
 vDt=vDt_Vdiv*vDtdiv; iDt=vyt_Vdiv*vytdiv/R; % iDt=[0.0035 0.0099 0.0198 0.0297 0.0396]Amp
 At= [iDt,ones(size(iDt))];
 tht=inv(At'*At)*(At'*vDt); RD_ont=tht(1,1), VD_ont=tht(2,1), % (12.55ohm,1.67V)
figure(2)
hold off, plot(-vDtdiv,vytdiv,'x'),
hold on, plot(-(RD_ont*iDt+VD_ont*ones(size(iDt)))/vDt_Vdiv,iDt*R/vyt_Vdiv) 
figure(3), 
hold off, plot(vDt,iDt,'x'),hold on, plot((RD_ont*iDt+VD_ont*ones(size(iDt))),iDt)
