clear all;
% Golubkov Andrej
% Test 21.Mai,2004

l_gruen=545*10^(-9);
l_blau=439*10^(-9);
n0=1.52;

dat1=load('gruen_gekreuzt.dat');
dat2=load('gruen_parallel.dat');

U1 = dat1(:,1);
I1 = dat1(:,2);
dU1 = dat1(:,3);
dI1 = (zeros(1,numel(U1))+1)';

U2 = dat2(:,1);
I2 = dat2(:,2);
dU2 = dat2(:,3);
dI2 = (zeros(1,numel(U2))+1)';

ndata = numel(U1);




figure(1);clf;
hold on;

p1=plot(U1,I1,'rx');
p2=herrorbar(U1,I1,dU1,'rx');
p3=plot(U2,I2,'rs');
p4=herrorbar(U2,I2,dU2,'rs');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Kurvenfit
%

eps = 0.00001;     %max relativer fehler


ma = 4;
a1 = [800, pi/3500, -pi/2,800];
a2 = [800, pi/3500, pi/2,800];

[a1,sd_a1,var1,covar1,c1] = mrqmin(U1,I1,dI1,ndata,ma,a1,eps);
[a2,sd_a2,var2,covar2,c2] = mrqmin(U2,I2,dI2,ndata,ma,a2,eps);
% Eingabe-Parameter:  x  Zeilenvektor der x-Komponenten der geg. Punkte
%                     y  Zeilenvektor der y-Komponenten der geg. Punkte
%                     sigig  Zeilenvektor der Standardabweichungen der geg. Punkte
%                     ndata  Zahl der geg. Punkte
%                     ma     Zahl der Fit-Parameter
%                     a      Zeilenvektor der guessed values fuer die Fit-Paramter
%                     eps    relativer Fehler der Fit-Parameter, der zu unterschreiten ist
%
% Ausgabe-Parameter:  a      Zeilenvektor der gefitteten Parameter
%                     sd_a   Zeilenvektor der Standardabweichungen der Parameter
%                     var    Varianz des Fits   Anfang und Ende des Sollbereichs
%                     covar  Kovarianz-Matrix (normiert gemaess Skriptum, S. 109)
U = [1:max(U1)];
p5=plot(U,a1(1)+sin(a1(2)*U + a1(3))*a1(4));
p6=plot(U,a2(1)+sin(a2(2)*U + a2(3))*a2(4));

r63_1=a1(2)*l_gruen / (2*pi*n0^3);
r63_2=a2(2)*l_gruen / (2*pi*n0^3);


disp('gruen gekreuzt, r63=');
disp(r63_1);

disp('gruen parallel, r63=');
disp(r63_2);


hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ax1=gca;
set(ax1,'XLim',[0,max(U1)+200])
%set(ax1,'YLim',[-0.02,1.2])

le1=legend([p1,p3],'grüner Filter, Polarisatoren gekreuzt','grüner Filter, Polarisatoren parallel',1);

xl1=xlabel('Spannung U / V');
yl1=ylabel('Intensität I');
%ti1=title('Ueberlagerte Lorentz- Profile');

%set(ax1,'FontSize',12)
set(xl1,'FontSize',13)
set(yl1,'FontSize',13)
%set(ti1,'FontSize',14)
%set(le1,'FontSize',12)
grid on;
