Home > atphysics > TuneAndChromaticity > fittune2.m

fittune2

PURPOSE ^

FITTUNE2 fits linear tunes of THERING using 2 quadrupole families

SYNOPSIS ^

function [dK, Jinv] = fittune2(newtunes, quadfam1, quadfam2, varargin);

DESCRIPTION ^

FITTUNE2 fits linear tunes of THERING using 2 quadrupole families
 FITTUNE2(NEWTUNES,QUADFAMILY1,QUADFAMILY2)
 [dK, Jinv] = FITTUNE2(NEWTUNES,QUADFAMILY1,QUADFAMILY2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dK, Jinv] =  fittune2(newtunes, quadfam1, quadfam2, varargin);
0002 %FITTUNE2 fits linear tunes of THERING using 2 quadrupole families
0003 % FITTUNE2(NEWTUNES,QUADFAMILY1,QUADFAMILY2)
0004 % [dK, Jinv] = FITTUNE2(NEWTUNES,QUADFAMILY1,QUADFAMILY2)
0005 
0006 % Must declare THERING as global in order for the function to modify quadrupole values
0007 global THERING
0008 if nargin > 3 % use externally supplied step size for quadrupole K-values
0009     delta = varargin{1}
0010 else
0011     delta = 1e-6; % default step size for quadrupole K-values
0012 end
0013 % find indexes of the 2 quadrupole families use for fitting
0014 Q1I = findcells(THERING,'FamName',quadfam1);
0015 Q2I = findcells(THERING,'FamName',quadfam2);
0016 
0017 InitialK1 = getcellstruct(THERING,'K',Q1I);
0018 InitialK2 = getcellstruct(THERING,'K',Q2I);
0019 
0020 
0021 % Compute initial tunes before fitting
0022 [ LD, InitialTunes] = linopt(THERING,0);
0023 
0024 TempTunes = InitialTunes;
0025 TempK1 = InitialK1;
0026 TempK2 = InitialK2;
0027 
0028 
0029 % Take Derivative
0030 THERING = setcellstruct(THERING,'K',Q1I,TempK1+delta);
0031 THERING = setcellstruct(THERING,'PolynomB',Q1I,TempK1+delta,2);
0032 [LD , Tunes_dK1 ] = linopt(THERING,0);
0033 THERING = setcellstruct(THERING,'K',Q1I,TempK1);
0034 THERING = setcellstruct(THERING,'PolynomB',Q1I,TempK1,2);
0035 THERING = setcellstruct(THERING,'K',Q2I,TempK2+delta);
0036 THERING = setcellstruct(THERING,'PolynomB',Q2I,TempK2+delta,2);
0037 [LD , Tunes_dK2 ] = linopt(THERING,0);
0038 THERING = setcellstruct(THERING,'K',Q2I,TempK2);
0039 THERING = setcellstruct(THERING,'PolynomB',Q2I,TempK2,2);
0040 
0041 %Construct the Jacobian
0042 J = ([Tunes_dK1(:) Tunes_dK2(:)] - [TempTunes(:) TempTunes(:)])/delta;
0043 Jinv = inv(J);
0044 
0045 dnu = (newtunes(:) - TempTunes(:));
0046 dK = Jinv*dnu;
0047 
0048 TempK1 = TempK1+dK(1);
0049 TempK2 = TempK2+dK(2);
0050 
0051 
0052 THERING = setcellstruct(THERING,'K',Q1I,TempK1);
0053 THERING = setcellstruct(THERING,'PolynomB',Q1I,TempK1,2);
0054 THERING = setcellstruct(THERING,'K',Q2I,TempK2);
0055 THERING = setcellstruct(THERING,'PolynomB',Q2I,TempK2,2);
0056 
0057 [LD,TempTunes] = linopt(THERING,0);
0058 S = sprintf('New tunes = %f %f\n', TempTunes(1), TempTunes(2));
0059 disp(S)
0060

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