Home > atmatch > atlinconstraint.m

atlinconstraint

PURPOSE ^

ATLINCONSTRAINT Generate a constraint on linear optics for atmatch

SYNOPSIS ^

function constraint = atlinconstraint(refpts,params,vmin,vmax,weight)

DESCRIPTION ^

ATLINCONSTRAINT Generate a constraint on linear optics for atmatch

CONSTRAINT=ATLINCONSTRAINT(REFPTS,PARAMS,VMIN,VMAX,WEIGHT)

REFPTS Row vector of selected positions
PARAMS Cell array describing the desired value at each position
       The length of params must be 1 or length(REFPTS)
       Each element of PARAMS is itself a cell array defining the field
       name and indices in the structure returned by atlinopt. Additional
       field names are: 'tune' and 'chromaticity'.
VMIN   Minimum value for the constraint
VMAX   Maximum value for the constraint

CONSTRAINT Row structure array to be used in atmatch

 REFPTS, PARAMS, VMIN, VMAX, WEIGHT must have the same length,
       or have length 1

 Example:
>> c1=atlinconstraint(1,{{'ClosedOrbit',{3}},{'ClosedOrbit',{4}}},[0 0],[0 0],[1/6 6]);

 See also: atmatch, AtVariableBuilder

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function constraint = atlinconstraint(refpts,params,vmin,vmax,weight)
0002 %ATLINCONSTRAINT Generate a constraint on linear optics for atmatch
0003 %
0004 %CONSTRAINT=ATLINCONSTRAINT(REFPTS,PARAMS,VMIN,VMAX,WEIGHT)
0005 %
0006 %REFPTS Row vector of selected positions
0007 %PARAMS Cell array describing the desired value at each position
0008 %       The length of params must be 1 or length(REFPTS)
0009 %       Each element of PARAMS is itself a cell array defining the field
0010 %       name and indices in the structure returned by atlinopt. Additional
0011 %       field names are: 'tune' and 'chromaticity'.
0012 %VMIN   Minimum value for the constraint
0013 %VMAX   Maximum value for the constraint
0014 %
0015 %CONSTRAINT Row structure array to be used in atmatch
0016 %
0017 % REFPTS, PARAMS, VMIN, VMAX, WEIGHT must have the same length,
0018 %       or have length 1
0019 %
0020 % Example:
0021 %>> c1=atlinconstraint(1,{{'ClosedOrbit',{3}},{'ClosedOrbit',{4}}},[0 0],[0 0],[1/6 6]);
0022 %
0023 % See also: atmatch, AtVariableBuilder
0024 
0025 if islogical(refpts), refpts=find(refpts); end
0026 exp=1:max(length(refpts),length(params));
0027 refp(1,exp)=refpts;
0028 pars(1,exp)=params;
0029 vmin(1,exp)=vmin;
0030 vmax(1,exp)=vmax;
0031 weight(1,exp)=weight;
0032 
0033 paramnames=cellfun(@(c) c{1},pars,'UniformOutput',false);
0034 tunes=strcmp('tune',paramnames);
0035 chrom=strcmp('chromaticity',paramnames);
0036 other=~(chrom|tunes);
0037 
0038 constraint=struct([]);
0039 if any(tunes)
0040     constraint=[constraint,struct(...
0041         'Fun',@(~,~,gd) cellfun(@(p) gd.fractune(p{2}{:}),pars(tunes)),...
0042         'Min',vmin(tunes),...
0043         'Max',vmax(tunes),...
0044         'RefPoints',refp(tunes),...
0045         'Weight',weight(tunes))];
0046 end
0047 if any(chrom)
0048     constraint=[constraint,struct(...
0049         'Fun',@(~,~,gd) cellfun(@(p) gd.chromaticity(p{2}{:}),pars(chrom)),...
0050         'Min',vmin(chrom),...
0051         'Max',vmax(chrom),...
0052         'RefPoints',refp(chrom),...
0053         'Weight',weight(chrom))];
0054 end
0055 if any(other)
0056     constraint=[constraint,struct(...
0057         'Fun',@(~,ld,~) arrayfun(@(lindata,p) getfield(lindata,p{1}{:}),ld,pars(other)),...
0058         'Min',vmin(other),...
0059         'Max',vmax(other),...
0060         'RefPoints',refp(other),...
0061         'Weight',weight(other))];
0062 end
0063 end

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