Greatfit.m (Matlab program fot fitting)

From New IAC Wiki
Revision as of 07:33, 29 October 2008 by Oborn (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

fid = fopen('datafile.m','r'); z = fscanf(fid, '%g'); fclose(fid); x=[0:4095]; time=[979:1999]; counts=([z(979:1999)])';

plot(x,z,'r'); xlabel('Channel'); ylabel('Number of Counts'); hold on modelFun = @(p,x) p(1).*exp((-(x-p(2)).^2)/(2*p(3).^2))+p(4).*exp((-(x-p(5)).^2)/(2*p(6).^2))+p(7).*exp((-(x-p(8)).^2)/(2*p(9).^2)); startingVals = [800 1150 100 500 1250 100 100 1450 300]; coefEsts = nlinfit(time, counts, modelFun, startingVals); xgrid = linspace(900,2000,1000); line(xgrid, modelFun(coefEsts, xgrid), 'Color','m'); plot(x, coefEsts(1).*exp((-(x-coefEsts(2)).^2)/(2*coefEsts(3).^2))+coefEsts(4).*exp((-(x-coefEsts(5)).^2)/(2*coefEsts(6).^2))+coefEsts(7).*exp((-(x-coefEsts(8)).^2)/(2*coefEsts(9).^2)),'g','LineWidth',1.5) axis([700 2500 0 1000]) xsmallarea=0:976; xlargearea=976:4095; ysmallarea=coefEsts(1).*exp((-(xsmallarea-coefEsts(2)).^2)/(2*coefEsts(3).^2))+coefEsts(4).*exp((-(xsmallarea-coefEsts(5)).^2)/(2*coefEsts(6).^2))+coefEsts(7).*exp((-(xsmallarea-coefEsts(8)).^2)/(2*coefEsts(9).^2)); ylargearea=coefEsts(1).*exp((-(xlargearea-coefEsts(2)).^2)/(2*coefEsts(3).^2))+coefEsts(4).*exp((-(xlargearea-coefEsts(5)).^2)/(2*coefEsts(6).^2))+coefEsts(7).*exp((-(xlargearea-coefEsts(8)).^2)/(2*coefEsts(9).^2)); SmallArea=trapz(xsmallarea,ysmallarea) LargeArea=trapz(xlargearea,ylargearea) Ratio_percent=100*SmallArea/(SmallArea+LargeArea)