Home > atphysics > TuneAndChromaticity > fitchrom2.m

fitchrom2

PURPOSE ^

FITCHROM2 fits chromaticity of THERING using 2 sextupole families

SYNOPSIS ^

function varargout = fitchrom2(newchrom, sextfam1, sextfam2, varargin);

DESCRIPTION ^

FITCHROM2 fits chromaticity  of THERING using 2 sextupole families
 FITCHROM2(NEWCHROM,SEXTUPOLEFAMILY1,SEXTUPOLEFAMILY2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout =  fitchrom2(newchrom, sextfam1, sextfam2, varargin);
0002 %FITCHROM2 fits chromaticity  of THERING using 2 sextupole families
0003 % FITCHROM2(NEWCHROM,SEXTUPOLEFAMILY1,SEXTUPOLEFAMILY2)
0004 
0005 % Must declare THERING as global in order for the function to modify sextupole values
0006 global THERING
0007 
0008 %make a column vector
0009 newchrom = newchrom(:);
0010 deltaS = 1e-5; % step size in Sextupole strngth
0011 deltaP = 1e-8;
0012 
0013 % find indexes of the 2 quadrupole families use for fitting
0014 S1I = findcells(THERING,'FamName',sextfam1);
0015 S2I = findcells(THERING,'FamName',sextfam2);
0016 InitialS1 = getcellstruct(THERING,'PolynomB',S1I,3);
0017 InitialS2 = getcellstruct(THERING,'PolynomB',S2I,3);
0018 
0019 % Compute initial tunes and chromaticities before fitting
0020 
0021 [ LD, InitialTunes] = linopt(THERING,0);
0022 [ LDdP, ITdP] =linopt(THERING,deltaP);
0023 
0024 InitialChrom = (ITdP-InitialTunes)/deltaP;
0025 
0026 TempTunes = InitialTunes;
0027 TempChrom = InitialChrom;
0028 TempS1 = InitialS1; 
0029 TempS2 = InitialS2;
0030 
0031 for i=1:5
0032         
0033     % Take Derivative
0034     THERING = setcellstruct(THERING,'PolynomB',S1I,TempS1+deltaS,3);
0035     [LD , Tunes_dS1 ] = linopt(THERING,0);
0036     [LD , Tunes_dS1dP ] = linopt(THERING,deltaP);
0037 
0038     THERING = setcellstruct(THERING,'PolynomB',S1I,TempS1,3);
0039     THERING = setcellstruct(THERING,'PolynomB',S2I,TempS2+deltaS,3);
0040     [LD , Tunes_dS2 ] = linopt(THERING,0);
0041     [LD , Tunes_dS2dP ] = linopt(THERING,deltaP);
0042     THERING = setcellstruct(THERING,'PolynomB',S2I,TempS2,3);
0043 
0044     %Construct the Jacobian
0045     Chrom_dS1 = (Tunes_dS1dP-Tunes_dS1)/deltaP;
0046     Chrom_dS2 = (Tunes_dS2dP-Tunes_dS2)/deltaP;
0047 
0048     J = ([Chrom_dS1(:) Chrom_dS2(:)] - [TempChrom(:) TempChrom(:)])/deltaS;
0049     Jinv = inv(J);
0050 
0051     dchrom = (newchrom(:) - TempChrom(:));
0052     dS = Jinv*dchrom;
0053 
0054     TempS1 = TempS1+dS(1);
0055     TempS2 = TempS2+dS(2);
0056 
0057     THERING = setcellstruct(THERING,'PolynomB',S1I,TempS1,3);
0058     THERING = setcellstruct(THERING,'PolynomB',S2I,TempS2,3);
0059 
0060     [ LD, TempTunes] = linopt(THERING,0);
0061     [ LD, TempTunesdP] = linopt(THERING,deltaP);
0062     TempChrom = (TempTunesdP-TempTunes)/deltaP;
0063     %disp(TempChrom);
0064 
0065 end

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005