0001 function [dK, Jinv] = fittune2(newtunes, quadfam1, quadfam2, varargin);
0002
0003
0004
0005
0006
0007 global THERING
0008 if nargin > 3
0009 delta = varargin{1}
0010 else
0011 delta = 1e-6;
0012 end
0013
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
0022 [ LD, InitialTunes] = linopt(THERING,0);
0023
0024 TempTunes = InitialTunes;
0025 TempK1 = InitialK1;
0026 TempK2 = InitialK2;
0027
0028
0029
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
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