FINDRESPM computes the change in the closed orbit due to parameter perturbations Two calling syntax options 1. FINDRESPM(RING, OBSINDEX, PERTURBINDEX, PVALUE, 'FIELD', M, N, ORBITFUNCTION, ARGS) 2. !!! not implemented yet FINDRESPM(RING, OBSINDEX, PERTURBGROUP, PVALUE, ORBITFUNCTION, ARGS) RING - ring lattice OBSINDEX - indexes of elements where the orbit is observed (at the entrance) PERTURBINDEX - Integer indexes of elements whose parameters are perturbed used with syntax 1 only. PERTURBGROUP - cell array of AT paramgroups. See ATPARAMGROUP used with syntax 2 only PVALUE - amount of peturbation (Numeric array or scalar if all perturbations are the same magnitude) FIELD,M,N are only use with syntax 1. FIELD - field name of the parameter to perturb (string) M,N - index in the matrix, if the field is a matrix For example to perturb the quadrupole field in a multipole element FIELD = 'PolynomB', M = 1, N = 2 ORBITFUNCTION - specifies which of the FINDORBIT functions is used 'findorbit4' (default) 'findsyncorbit' 'findorbit6' ARGS - additioanl arguments may be passsed to some of the FINDORBIT functions findorbit4 - constant momentum error dP findsyncorbit - fixed orbit lengthening dCT Returns a 1-by-4 cell array of O-by-P matrixes where O = length(OBSINDEX) and P = length(PERTURB) one for each of the close orbit components: X, PX, Y, PY See also ATPARAMGROUP, FINDORBIT, FINDORBIT4, FINDORBIT6, FINDSYNCORBIT
0001 function C = findrespm(RING, OBSINDEX, PERTURB, PVALUE, varargin) 0002 %FINDRESPM computes the change in the closed orbit due to parameter perturbations 0003 % Two calling syntax options 0004 % 1. FINDRESPM(RING, OBSINDEX, PERTURBINDEX, PVALUE, 'FIELD', M, N, ORBITFUNCTION, ARGS) 0005 % 2. !!! not implemented yet FINDRESPM(RING, OBSINDEX, PERTURBGROUP, PVALUE, ORBITFUNCTION, ARGS) 0006 % 0007 % RING - ring lattice 0008 % OBSINDEX - indexes of elements where the orbit is observed (at the entrance) 0009 % PERTURBINDEX - Integer indexes of elements whose parameters are perturbed 0010 % used with syntax 1 only. 0011 % 0012 % PERTURBGROUP - cell array of AT paramgroups. See ATPARAMGROUP 0013 % used with syntax 2 only 0014 % 0015 % PVALUE - amount of peturbation 0016 % (Numeric array or scalar if all perturbations are the same magnitude) 0017 % 0018 % FIELD,M,N are only use with syntax 1. 0019 % 0020 % FIELD - field name of the parameter to perturb (string) 0021 % 0022 % M,N - index in the matrix, if the field is a matrix 0023 % For example to perturb the quadrupole field in a 0024 % multipole element 0025 % FIELD = 'PolynomB', M = 1, N = 2 0026 % 0027 % ORBITFUNCTION - specifies which of the FINDORBIT functions is used 0028 % 0029 % 'findorbit4' (default) 0030 % 'findsyncorbit' 0031 % 'findorbit6' 0032 % 0033 % ARGS - additioanl arguments may be passsed to some of the FINDORBIT functions 0034 % findorbit4 - constant momentum error dP 0035 % findsyncorbit - fixed orbit lengthening dCT 0036 % 0037 % 0038 % Returns a 1-by-4 cell array of O-by-P matrixes 0039 % where O = length(OBSINDEX) and P = length(PERTURB) 0040 % one for each of the close orbit components: X, PX, Y, PY 0041 % See also ATPARAMGROUP, FINDORBIT, FINDORBIT4, FINDORBIT6, FINDSYNCORBIT 0042 0043 0044 O = length(OBSINDEX); 0045 P = length(PERTURB); 0046 C = {zeros(O,P),zeros(O,P),zeros(O,P),zeros(O,P)}; 0047 0048 if length(PVALUE) ~= P 0049 PVALUE = PVALUE(ones(1,P(1))); 0050 end 0051 0052 0053 if isnumeric(PERTURB) % syntax option 1 0054 % Integer indexes of perturbed elements. 0055 % More fields must be supplied. 0056 % setfield will be used to make perturbations 0057 if nargin < 7 0058 error('Incorrect number of inputs'); 0059 end 0060 0061 if ~ischar(varargin{1}) % Check that the FIELD argument is a string 0062 error('The 5-th argument FIELD must be a string'); 0063 end 0064 0065 if ~isnumeric(varargin{2}) | length(varargin{2})>1 % Check that the M argument is a scalar 0066 error('The 6-th argument FIELD must be a scalar'); 0067 end 0068 M = varargin{2}(1); 0069 0070 if ~isnumeric(varargin{3}) | length(varargin{3})>1 % Check that the M argument is a scalar 0071 error('The 7-th argument FIELD must be a scalar'); 0072 end 0073 N = varargin{3}(1); 0074 0075 if nargin > 7 0076 ORBITFUNCTION = varargin{4}; 0077 else 0078 ORBITFUNCTION = 'findorbit4'; 0079 end 0080 0081 0082 switch ORBITFUNCTION 0083 case 'findorbit4' 0084 orbit_function_handle = @findorbit4; 0085 if nargin == 9 0086 orbit_function_args = {varargin{5}, OBSINDEX}; 0087 else 0088 orbit_function_args = {0, OBSINDEX}; 0089 end 0090 case 'findsyncorbit' 0091 orbit_function_handle = @findsyncorbit; 0092 if nargin == 9 0093 orbit_function_args = {varargin{5}, OBSINDEX}; 0094 else 0095 orbit_function_args = {0, OBSINDEX}; 0096 end 0097 case 'findorbit6' 0098 orbit_function_handle = @findorbit6; 0099 orbit_function_args = {OBSINDEX}; 0100 otherwise 0101 error(['Unknown FINDORBIT function: ',ORBITFUNCTION]); 0102 end 0103 0104 %ORBIT = findorbit4(RING,0,OBSINDEX); 0105 0106 0107 ORBIT = feval(orbit_function_handle,RING,orbit_function_args{:}); 0108 0109 mn = {M,N}; 0110 for i = 1:P 0111 oldvalue = getfield(RING{PERTURB(i)},varargin{1},mn); 0112 RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue+PVALUE(i)); 0113 ORBITPLUS = feval(orbit_function_handle,RING,orbit_function_args{:}); 0114 RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue); 0115 DORBIT = (ORBITPLUS - ORBIT); 0116 C{1}(:,i) = DORBIT(1,:); 0117 C{2}(:,i) = DORBIT(2,:); 0118 C{3}(:,i) = DORBIT(3,:); 0119 C{4}(:,i) = DORBIT(4,:); 0120 end 0121 end