MATLAB calculations

From OpenWetWare

Jump to: navigation, search
%% First I define fixed constants

R=6.75e-2; % in m
muo=4*pi*(1e-7);
muB=9.274e-24; %using J
h=6.626e-34; %using J
N=320;

%% The data is then used to calculate the B-field through the Helmholtz 
%coils and the sample

%SMALL
datS=[90.00 	1.839;
      85.00 	1.766;
      80.00 	1.685;
      75.00 	1.567;
      70.00 	1.477;];
fqS=(1e6)*datS(:,1)';
iS=datS(:,2)';
BS=((4/5)^(3/2))*((muo*N*iS)/R);

%MEDIUM
datM=[70.00 	1.335
      65.00 	1.253
      60.00 	1.171
      55.00 	1.071
      50.00 	0.972
      45.00 	0.898
      40.00 	0.790
      35.00 	0.690
      30.00 	0.591
      25.00 	0.492];
fqM=(1e6)*datM(:,1)';
iM=datM(:,2)';
BM=((4/5)^(3/2))*((muo*N*iM)/R);

%Large
datL=[30.00 	0.581
      26.00 	0.472
      22.00 	0.427
      18.00 	0.355
      14.00 	0.265];
fqL=(1e6)*datL(:,1)';
iL=datL(:,2)';
BL=((4/5)^(3/2))*((muo*N*iL)/R);

%% Now I calculate g_s for each data pair and then from linear least square
% fits for the 3 data sets

gSmall=(h*fqS)./(muB*BS)
gSmean=mean(gSmall)
gMed=(h*fqM)./(muB*BM)
gMmean=mean(gMed)
gLarge=(h*fqL)./(muB*BL)
gLmean=mean(gLarge)
gTot=(gSmean+gMmean+gLmean)/3

Sfit=polyfit(BS,(h*fqS)/muB,1)
Sval=polyval(Sfit,BS)
Mfit=polyfit(BM,(h*fqM)/muB,1)
Mval=polyval(Mfit,BM)
Lfit=polyfit(BL,(h*fqL)/muB,1)
Lval=polyval(Lfit,BL)
AvgFit=(Sfit(1)+Mfit(1)+Lfit(1))/3
figure(1)
plot(BS,Sval,BS,(h*fqS)/muB,'r*');title('B vs.(h*v)/muB for small coil'),xlabel('T'),ylabel('T')
saveas(figure(1),'smallcoil.jpg')
figure(2)
plot(BM,Mval,BM,(h*fqM)/muB,'r*');title('B vs.(h*v)/muB for medium coil'),xlabel('T'),ylabel('T')
saveas(figure(2),'mediumcoil.jpg')
figure(3)
plot(BL,Lval,BL,(h*fqL)/muB,'r*');title('B vs.(h*v)/muB for large coil'),xlabel('T'),ylabel('T')
saveas(figure(3),'largecoil.jpg')

sdmS=sqrt(sum((gSmall-gSmean).^2)*(1/(length(gSmall)*(length(gSmall)-1))))
sdmM=sqrt(sum((gMed-gMmean).^2)*(1/(length(gMed)*(length(gMed)-1))))
sdmL=sqrt(sum((gLarge-gLmean).^2)*(1/(length(gLarge)*(length(gLarge)-1))))
sdmTot=(sdmS+sdmM+sdmL)/3
Personal tools