Home > pubtools > LatticeTuningFunctions > correction > response_matrix > findrespmat.m

findrespmat

PURPOSE ^

FINDRESPM_mod computes the change in the closed orbit due to parameter perturbations

SYNOPSIS ^

function C = findrespmat(RING, OBSINDEX, PERTURB, PVALUE, varargin)

DESCRIPTION ^

FINDRESPM_mod computes the change in the closed orbit due to parameter perturbations
 Two calling syntax options
 1. FINDRESPM_mod(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)
             'findorbit4Err'
             'findsyncorbit'
             'findorbit6'
             'findorbit6Err'
             'findtrajectory6Err'
             'finddispersion6Err'
             'gettunechromatlinopt'


 ARGS - additioanl arguments may be passsed to some of the FINDORBIT functions
             findorbit4     - constant momentum error dP
             findorbit4Err     - constant momentum error dP
             findsyncorbit  - fixed orbit lengthening dCT
             findorbit6     - inCOD
             findorbit6err  - inCOD
             findtrajectory6err   - inCOD
             finddispersion6Err   - indrfc,alpha,delta,inCOD
             gettunechromatlinopt - inCOD

 2 sided matrix is computed (Oplus-Ominus)/2

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function C = findrespmat(RING, OBSINDEX, PERTURB, PVALUE, varargin)
0002 %FINDRESPM_mod computes the change in the closed orbit due to parameter perturbations
0003 % Two calling syntax options
0004 % 1. FINDRESPM_mod(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 %             'findorbit4Err'
0031 %             'findsyncorbit'
0032 %             'findorbit6'
0033 %             'findorbit6Err'
0034 %             'findtrajectory6Err'
0035 %             'finddispersion6Err'
0036 %             'gettunechromatlinopt'
0037 %
0038 %
0039 % ARGS - additioanl arguments may be passsed to some of the FINDORBIT functions
0040 %             findorbit4     - constant momentum error dP
0041 %             findorbit4Err     - constant momentum error dP
0042 %             findsyncorbit  - fixed orbit lengthening dCT
0043 %             findorbit6     - inCOD
0044 %             findorbit6err  - inCOD
0045 %             findtrajectory6err   - inCOD
0046 %             finddispersion6Err   - indrfc,alpha,delta,inCOD
0047 %             gettunechromatlinopt - inCOD
0048 %
0049 % 2 sided matrix is computed (Oplus-Ominus)/2
0050 %
0051 % Returns a 1-by-4 cell array of O-by-P matrixes
0052 % where O = length(OBSINDEX) and P = length(PERTURB)
0053 % one for each of the close orbit components: X, PX, Y, PY
0054 % See also ATPARAMGROUP, FINDORBIT, FINDORBIT4, FINDORBIT6, FINDSYNCORBIT
0055 
0056 warning('off','all');
0057 
0058 O = length(OBSINDEX);
0059 P = length(PERTURB);
0060 C = {zeros(O,P),zeros(O,P),zeros(O,P),zeros(O,P)};
0061 
0062 if length(PVALUE) ~= P
0063     PVALUE = PVALUE(ones(1,P(1)));
0064 end
0065 
0066 
0067 if isnumeric(PERTURB)   % syntax option 1
0068     % Integer indexes of perturbed elements.
0069     % More fields must be supplied.
0070     % setfield will be used to make perturbations
0071     if nargin < 7
0072         error('Incorrect number of inputs');
0073     end
0074     
0075     if ~ischar(varargin{1}) % Check that the FIELD argument is a string
0076         error('The 5-th argument FIELD must be a string');
0077     end
0078     
0079     if ~isnumeric(varargin{2}) | length(varargin{2})>1 % Check that the M argument is a scalar
0080         error('The 6-th argument FIELD must be a scalar');
0081     end
0082     M = varargin{2}(1);
0083     
0084     if ~isnumeric(varargin{3}) | length(varargin{3})>1 % Check that the M argument is a scalar
0085         error('The 7-th argument FIELD must be a scalar');
0086     end
0087     N = varargin{3}(1);
0088     
0089     if nargin > 7
0090         ORBITFUNCTION = varargin{4};
0091     else
0092         ORBITFUNCTION = 'findorbit4';
0093     end
0094     
0095     
0096     switch ORBITFUNCTION
0097         case 'findorbit4'
0098             orbit_function_handle = @findorbit4;
0099             if nargin == 9
0100                 orbit_function_args   = {varargin{5}, OBSINDEX};
0101             else
0102                 
0103                 orbit_function_args   = {0, OBSINDEX};
0104             end
0105         case 'findorbit4Err'
0106             orbit_function_handle = @findorbit4Err;
0107             if nargin == 9
0108                 orbit_function_args   = {varargin{5}, OBSINDEX};
0109             else
0110                 
0111                 orbit_function_args   = {0, OBSINDEX};
0112             end
0113         case 'findsyncorbit'
0114             orbit_function_handle = @findsyncorbit;
0115             if nargin == 9
0116                 orbit_function_args   = {varargin{5}, OBSINDEX};
0117             else
0118                 orbit_function_args   = {0, OBSINDEX};
0119             end
0120         case 'findorbit6'
0121             orbit_function_handle = @findorbit6;
0122             orbit_function_args   = {OBSINDEX};
0123             
0124         case 'findorbit6Err'
0125             orbit_function_handle = @findorbit6Err;
0126             orbit_function_args   = {OBSINDEX,varargin{5}};
0127             
0128         case 'findtrajectory6Err'
0129             orbit_function_handle = @findtrajectory6Err;
0130             orbit_function_args   = {OBSINDEX,varargin{5}};
0131             
0132         case 'finddispersion6Err'
0133             orbit_function_handle = @finddispersion6Err;
0134             orbit_function_args   = {OBSINDEX,varargin{5},varargin{6},varargin{7},varargin{8}};
0135             
0136         case 'gettunechromatlinopt'
0137             orbit_function_handle = @gettunechromatlinopt;
0138             orbit_function_args   = {varargin{5}};
0139             
0140             
0141         otherwise
0142             error(['Unknown FINDORBIT function: ',ORBITFUNCTION]);
0143     end
0144     
0145     %ORBIT = findorbit4(RING,0,OBSINDEX);
0146     
0147     ORBIT = feval(orbit_function_handle,RING,orbit_function_args{:});
0148     
0149     mn = {M,N};
0150     for i = 1:P
0151         
0152         oldvalue = getfield(RING{PERTURB(i)},varargin{1},mn);
0153         RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue+PVALUE(i));
0154         ORBITPLUS  = feval(orbit_function_handle,RING,orbit_function_args{:});
0155         RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue-PVALUE(i));
0156         ORBITMINUS  = feval(orbit_function_handle,RING,orbit_function_args{:});
0157         RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue);
0158         DORBIT = (ORBITPLUS - ORBITMINUS)/2;
0159         %ORBITMINU  = feval(orbit_function_handle,RING,orbit_function_args{:});
0160         %RING{PERTURB(i)} = setfield(RING{PERTURB(i)},varargin{1},mn,oldvalue);
0161         %DORBIT = (ORBITPLUS - ORBITMINU)/2;
0162         C{1}(:,i) = DORBIT(1,:);
0163         C{2}(:,i) = DORBIT(2,:);
0164         C{3}(:,i) = DORBIT(3,:);
0165         C{4}(:,i) = DORBIT(4,:);
0166     end
0167 end
0168 
0169 warning('on','all');
0170

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