function arcchrom0=atmatchchromdelta(arc,c,sxtfams) arc : at lattice c : chromaticity to get size(c)=[2,1] sxtfams: {[findcells(arc,'FamName','SF1','SF2')],... [findcells(arc,'FamName','SD1','SD2')] } adds a common DKsext on the two specified sextupole families see also: atmatch
0001 function [arcchrom0,deltsext]=atmatchchromdelta(arc,c,sxtfams) 0002 % function arcchrom0=atmatchchromdelta(arc,c,sxtfams) 0003 % 0004 % arc : at lattice 0005 % c : chromaticity to get size(c)=[2,1] 0006 % sxtfams: {[findcells(arc,'FamName','SF1','SF2')],... 0007 % [findcells(arc,'FamName','SD1','SD2')] } 0008 % 0009 % adds a common DKsext on the two specified sextupole families 0010 % 0011 %see also: atmatch 0012 0013 disp('match chromaticity') 0014 0015 variabs=[]; 0016 0017 for isextfams=1:length(sxtfams) 0018 Ksf=cellfun(@(a)a.PolynomB(3),arc(sxtfams{isextfams}),'un',1); 0019 variabs=[variabs, atVariableBuilder(arc,... 0020 {@(r,DKsext)setcellstruct(r,'PolynomB',sxtfams{isextfams},Ksf+DKsext,1,3)},... 0021 {[0]})]; %#ok<*AGROW> 0022 end 0023 0024 % Ksf=cellfun(@(a)a.PolynomB(3),arc(sxtfams{1}),'un',1); 0025 % Ksd=cellfun(@(a)a.PolynomB(3),arc(sxtfams{2}),'un',1); 0026 0027 ConstrChrom=[... 0028 atlinconstraint(1,{{'chromaticity',{1}}},c(1),c(1),1)... 0029 atlinconstraint(1,{{'chromaticity',{2}}},c(2),c(2),1)]; 0030 0031 tol=1e-4; 0032 [arcchrom0,deltsext]=atmatch(arc,variabs,ConstrChrom,tol,150,0);%,@lsqnonlin); 0033 0034 % tol=1e-8; 0035 % arcchrom0=atmatch(arc,variabs,ConstrChrom,tol,50,3,@lsqnonlin); 0036 0037 % Ksfc=cellfun(@(a)a.PolynomB(3),arcchrom0(sxtfams{1}),'un',1); 0038 % Ksdc=cellfun(@(a)a.PolynomB(3),arcchrom0(sxtfams{2}),'un',1); 0039 % DSF=Ksfc-Ksf; 0040 % DSD=Ksdc-Ksd; 0041 0042 return 0043 0044