0001 function newring=atfitchrom(ring,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if isscalar(varargin{1}) && isnumeric(varargin{1})
0017 dpp=varargin{1};
0018 [newchrom,famname1,famname2]=deal(varargin{2:end});
0019 else
0020 dpp=0;
0021 [newchrom,famname1,famname2]=deal(varargin{:});
0022 end
0023 deltaP = 1e-8;
0024 idx1=varelem(ring,famname1);
0025 idx2=varelem(ring,famname2);
0026 kl1=atgetfieldvalues(ring(idx1),'PolynomB',{3});
0027 kl2=atgetfieldvalues(ring(idx2),'PolynomB',{3});
0028 if true
0029 deltaS = 1e-5;
0030
0031
0032 chrom=getchrom(ring,dpp,deltaP);
0033
0034
0035 chrom1 = getchrom(setsx(ring,idx1,kl1,deltaS),dpp,deltaP);
0036 chrom2 = getchrom(setsx(ring,idx2,kl2,deltaS),dpp,deltaP);
0037
0038
0039 J = ([chrom1(:) chrom2(:)] - [chrom(:) chrom(:)])/deltaS;
0040 dK = J\(newchrom(:)-chrom(:));
0041 else
0042 dK=fminsearch(@funchrom,[0;0],...
0043 optimset(optimset('fminsearch'),'Display','iter',...
0044 'TolX',1.e-5,'TolFun',1.e-8));
0045 end
0046 newring=setsx(ring,idx1,kl1,dK(1));
0047 newring=setsx(newring,idx2,kl2,dK(2));
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 function ring2=setsx(ring,idx,k0,delta)
0059 ring2=atsetfieldvalues(ring,idx,'PolynomB',{3},k0*(1+delta));
0060 end
0061
0062 function res=varelem(ring,arg)
0063 if islogical(arg)
0064 res=arg;
0065 elseif isnumeric(arg)
0066 res=false(size(ring));
0067 res(arg)=true;
0068 elseif ischar(arg)
0069 res=atgetcells(ring,'FamName',arg);
0070 elseif iscell(arg)
0071 res=false(size(ring));
0072 for i=1:length(arg)
0073 res=res|varelem(ring,arg{i});
0074 end
0075 else
0076 error('AT:GetElemList:WrongArg','Cannot parse argument');
0077 end
0078 end
0079
0080 function chrom=getchrom(ring,dpp,deltaP)
0081 [lindata, tunesa] = atlinopt(ring,dpp);
0082 [lindata, tunesb] = atlinopt(ring,dpp+deltaP);
0083 chrom = (tunesb-tunesa)/deltaP;
0084 end
0085 end