1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of findm44</title> |
---|
6 | <meta name="keywords" content="findm44"> |
---|
7 | <meta name="description" content="FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice"> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../../index.html">Home</a> > <a href="../index.html">at</a> > <a href="index.html">atphysics</a> > findm44.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for at/atphysics <img alt=">" border="0" src="../../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>findm44 |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
24 | <div class="box"><strong>FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function [M44, varargout] = findm44(LATTICE,DP,varargin) </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice |
---|
31 | for a particle with relative momentum deviation DP |
---|
32 | |
---|
33 | IMPORTANT!!! FINDM44 assumes constant momentum deviation. |
---|
34 | PassMethod used for any element in the LATTICE SHOULD NOT |
---|
35 | 1.change the longitudinal momentum dP |
---|
36 | (cavities , magnets with radiation, ...) |
---|
37 | 2.have any time dependence (localized impedance, fast kickers, ...) |
---|
38 | |
---|
39 | M44 = FINDM44(LATTICE,DP) finds a full one-turn |
---|
40 | matrix at the entrance of the first element |
---|
41 | !!! With this syntax FINDM44 assumes that the LATTICE |
---|
42 | is a ring and first finds the closed orbit |
---|
43 | |
---|
44 | [M44,T] = FINDM44(LATTICE,DP,REFPTS) also returns |
---|
45 | 4-by-4 transfer matrixes between entrance of |
---|
46 | the first element and each element indexed by REFPTS. |
---|
47 | T is 4-by-4-by-length(REFPTS) 3 dimensional array |
---|
48 | so that the set of indexes (:,:,i) selects the 4-by-4 |
---|
49 | matrix at the i-th reference point. |
---|
50 | |
---|
51 | Note: REFPTS is an array of increasing indexes that |
---|
52 | select elements from range 1 to length(LATTICE)+1. |
---|
53 | See further explanation of REFPTS in the 'help' for FINDSPOS |
---|
54 | When REFPTS= [ 1 2 .. ] the first point is the entrance of the |
---|
55 | first element and T(:,:,1) - identity matrix |
---|
56 | |
---|
57 | Note: REFPTS is allowed to go 1 point beyond the |
---|
58 | number of elements. In this case the last point is |
---|
59 | the EXIT of the last element. If LATTICE is a RING |
---|
60 | it is also the entrance of the first element |
---|
61 | after 1 turn: T(:,:,end) = M |
---|
62 | |
---|
63 | [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN) - Does not search for |
---|
64 | closed orbit. Instead the ORBITIN,a 1-by-6 vector of initial |
---|
65 | conditions is used: [x0, px0, y0, py0, DP, 0]' where |
---|
66 | the same DP as argument 2. The sixth component is ignored. |
---|
67 | This syntax is useful to specify the entrance orbit |
---|
68 | if LATTICE is not a ring or to avoid recomputing the |
---|
69 | closed orbit if is already known. |
---|
70 | |
---|
71 | [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN,'full') - same as above except |
---|
72 | matrixes returned in T are full 1-turn matrixes at the entrance of each |
---|
73 | element indexed by REFPTS. |
---|
74 | |
---|
75 | [M44, T, orbit] = FINDM44(...) in addition returns |
---|
76 | at REFPTS the closed orbit calculated along the |
---|
77 | way with findorbit4 |
---|
78 | |
---|
79 | See also LINEPASS, LATTICEPASS, <a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">FINDORBIT4</a>, <a href="findspos.html" class="code" title="function spos = findspos(LINE,REFPTS)">FINDSPOS</a></pre></div> |
---|
80 | |
---|
81 | <!-- crossreference --> |
---|
82 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
83 | This function calls: |
---|
84 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
85 | <li><a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">findorbit4</a> FINDORBIT4 finds closed orbit in the 4-d transverse phase</li></ul> |
---|
86 | This function is called by: |
---|
87 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
88 | <li><a href="linopt.html" class="code" title="function [LinData, varargout] = linopt(RING,DP,varargin);">linopt</a> LINOPT performs linear analysis of the COUPLED lattices</li><li><a href="tunechrom.html" class="code" title="function [tune, varargout] = tunechrom(RING,DP,varargin)">tunechrom</a> TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED lattice</li><li><a href="twissline.html" class="code" title="function [TD, varargout] = twissline(LINE,DP,TWISSDATAIN,varargin);">twissline</a> TWISSLINE calculates linear optics functions for an UNCOUPLED transport line</li><li><a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">twissring</a> TWISSRING calculates linear optics functions for an UNCOUPLED ring</li></ul> |
---|
89 | <!-- crossreference --> |
---|
90 | |
---|
91 | |
---|
92 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
93 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [M44, varargout] = findm44(LATTICE,DP,varargin)</a> |
---|
94 | 0002 <span class="comment">%FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice</span> |
---|
95 | 0003 <span class="comment">% for a particle with relative momentum deviation DP</span> |
---|
96 | 0004 <span class="comment">%</span> |
---|
97 | 0005 <span class="comment">% IMPORTANT!!! FINDM44 assumes constant momentum deviation.</span> |
---|
98 | 0006 <span class="comment">% PassMethod used for any element in the LATTICE SHOULD NOT</span> |
---|
99 | 0007 <span class="comment">% 1.change the longitudinal momentum dP</span> |
---|
100 | 0008 <span class="comment">% (cavities , magnets with radiation, ...)</span> |
---|
101 | 0009 <span class="comment">% 2.have any time dependence (localized impedance, fast kickers, ...)</span> |
---|
102 | 0010 <span class="comment">%</span> |
---|
103 | 0011 <span class="comment">% M44 = FINDM44(LATTICE,DP) finds a full one-turn</span> |
---|
104 | 0012 <span class="comment">% matrix at the entrance of the first element</span> |
---|
105 | 0013 <span class="comment">% !!! With this syntax FINDM44 assumes that the LATTICE</span> |
---|
106 | 0014 <span class="comment">% is a ring and first finds the closed orbit</span> |
---|
107 | 0015 <span class="comment">%</span> |
---|
108 | 0016 <span class="comment">% [M44,T] = FINDM44(LATTICE,DP,REFPTS) also returns</span> |
---|
109 | 0017 <span class="comment">% 4-by-4 transfer matrixes between entrance of</span> |
---|
110 | 0018 <span class="comment">% the first element and each element indexed by REFPTS.</span> |
---|
111 | 0019 <span class="comment">% T is 4-by-4-by-length(REFPTS) 3 dimensional array</span> |
---|
112 | 0020 <span class="comment">% so that the set of indexes (:,:,i) selects the 4-by-4</span> |
---|
113 | 0021 <span class="comment">% matrix at the i-th reference point.</span> |
---|
114 | 0022 <span class="comment">%</span> |
---|
115 | 0023 <span class="comment">% Note: REFPTS is an array of increasing indexes that</span> |
---|
116 | 0024 <span class="comment">% select elements from range 1 to length(LATTICE)+1.</span> |
---|
117 | 0025 <span class="comment">% See further explanation of REFPTS in the 'help' for FINDSPOS</span> |
---|
118 | 0026 <span class="comment">% When REFPTS= [ 1 2 .. ] the first point is the entrance of the</span> |
---|
119 | 0027 <span class="comment">% first element and T(:,:,1) - identity matrix</span> |
---|
120 | 0028 <span class="comment">%</span> |
---|
121 | 0029 <span class="comment">% Note: REFPTS is allowed to go 1 point beyond the</span> |
---|
122 | 0030 <span class="comment">% number of elements. In this case the last point is</span> |
---|
123 | 0031 <span class="comment">% the EXIT of the last element. If LATTICE is a RING</span> |
---|
124 | 0032 <span class="comment">% it is also the entrance of the first element</span> |
---|
125 | 0033 <span class="comment">% after 1 turn: T(:,:,end) = M</span> |
---|
126 | 0034 <span class="comment">%</span> |
---|
127 | 0035 <span class="comment">% [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN) - Does not search for</span> |
---|
128 | 0036 <span class="comment">% closed orbit. Instead the ORBITIN,a 1-by-6 vector of initial</span> |
---|
129 | 0037 <span class="comment">% conditions is used: [x0, px0, y0, py0, DP, 0]' where</span> |
---|
130 | 0038 <span class="comment">% the same DP as argument 2. The sixth component is ignored.</span> |
---|
131 | 0039 <span class="comment">% This syntax is useful to specify the entrance orbit</span> |
---|
132 | 0040 <span class="comment">% if LATTICE is not a ring or to avoid recomputing the</span> |
---|
133 | 0041 <span class="comment">% closed orbit if is already known.</span> |
---|
134 | 0042 <span class="comment">%</span> |
---|
135 | 0043 <span class="comment">% [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN,'full') - same as above except</span> |
---|
136 | 0044 <span class="comment">% matrixes returned in T are full 1-turn matrixes at the entrance of each</span> |
---|
137 | 0045 <span class="comment">% element indexed by REFPTS.</span> |
---|
138 | 0046 <span class="comment">%</span> |
---|
139 | 0047 <span class="comment">% [M44, T, orbit] = FINDM44(...) in addition returns</span> |
---|
140 | 0048 <span class="comment">% at REFPTS the closed orbit calculated along the</span> |
---|
141 | 0049 <span class="comment">% way with findorbit4</span> |
---|
142 | 0050 <span class="comment">%</span> |
---|
143 | 0051 <span class="comment">% See also LINEPASS, LATTICEPASS, FINDORBIT4, FINDSPOS</span> |
---|
144 | 0052 |
---|
145 | 0053 <span class="comment">% *************************************************************************</span> |
---|
146 | 0054 <span class="comment">% The numerical differentiation in FINDM44 uses symmetric form</span> |
---|
147 | 0055 <span class="comment">%</span> |
---|
148 | 0056 <span class="comment">% F(x+delta) - F(x-delta)</span> |
---|
149 | 0057 <span class="comment">% --------------------------------------</span> |
---|
150 | 0058 <span class="comment">% 2*delta</span> |
---|
151 | 0059 <span class="comment">%</span> |
---|
152 | 0060 <span class="comment">% with optimal differentiation step delta given by !!!! DO LATER</span> |
---|
153 | 0061 <span class="comment">% The relative error in the derivative computed this way</span> |
---|
154 | 0062 <span class="comment">% is !!!!!!!!!!!!!!!!! DO LATER</span> |
---|
155 | 0063 <span class="comment">% Reference: Numerical Recipes.</span> |
---|
156 | 0064 |
---|
157 | 0065 |
---|
158 | 0066 <span class="keyword">if</span> ~iscell(LATTICE) |
---|
159 | 0067 error(<span class="string">'First argument must be a cell array'</span>); |
---|
160 | 0068 <span class="keyword">end</span> |
---|
161 | 0069 |
---|
162 | 0070 NE = length(LATTICE); |
---|
163 | 0071 |
---|
164 | 0072 |
---|
165 | 0073 <span class="keyword">switch</span> nargin |
---|
166 | 0074 <span class="keyword">case</span> 5 <span class="comment">% FINDM44(LATTICE,DP,REFPTS,ORBITIN,'full')</span> |
---|
167 | 0075 <span class="keyword">if</span>(lower(varargin{3})==<span class="string">'full'</span>) |
---|
168 | 0076 FULLFLAG = 1; |
---|
169 | 0077 REFPTS = varargin{1}; |
---|
170 | 0078 R0 = varargin{2}; |
---|
171 | 0079 R0(5) = DP; |
---|
172 | 0080 R0(6)= 0; |
---|
173 | 0081 <span class="keyword">else</span> |
---|
174 | 0082 error(<span class="string">'Fifth argument - unknown option'</span>) |
---|
175 | 0083 <span class="keyword">end</span> |
---|
176 | 0084 <span class="keyword">case</span> 4 <span class="comment">% FINDM44(LATTICE,DP,REFPTS,ORBITIN)</span> |
---|
177 | 0085 FULLFLAG = 0; |
---|
178 | 0086 REFPTS = varargin{1}; |
---|
179 | 0087 R0 = varargin{2}; |
---|
180 | 0088 R0(5) = DP; |
---|
181 | 0089 R0(6)= 0; |
---|
182 | 0090 <span class="keyword">case</span> 3 <span class="comment">% FINDM44(LATTICE,DP,REFPTS)</span> |
---|
183 | 0091 FULLFLAG = 0; |
---|
184 | 0092 REFPTS = varargin{1}; |
---|
185 | 0093 R0 = [<a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">findorbit4</a>(LATTICE,DP);DP;0]; |
---|
186 | 0094 <span class="keyword">case</span> 2 <span class="comment">% FINDM44(LATTICE,DP)</span> |
---|
187 | 0095 REFPTS = NE+1; |
---|
188 | 0096 FULLFLAG = 0; |
---|
189 | 0097 R0 = [<a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">findorbit4</a>(LATTICE,DP);DP;0]; |
---|
190 | 0098 <span class="keyword">otherwise</span> |
---|
191 | 0099 error(<span class="string">'Incorrect number of input arguments'</span>); |
---|
192 | 0100 <span class="keyword">end</span> |
---|
193 | 0101 |
---|
194 | 0102 NR = length(REFPTS); |
---|
195 | 0103 |
---|
196 | 0104 |
---|
197 | 0105 <span class="comment">% Determine step size to use for numerical differentiation</span> |
---|
198 | 0106 <span class="keyword">global</span> NUMDIFPARAMS |
---|
199 | 0107 |
---|
200 | 0108 <span class="keyword">if</span> isfield(NUMDIFPARAMS,<span class="string">'XYStep'</span>) |
---|
201 | 0109 d = NUMDIFPARAMS.XYStep'; |
---|
202 | 0110 <span class="keyword">else</span> |
---|
203 | 0111 <span class="comment">% optimal differentiation step - Numerical Recipes</span> |
---|
204 | 0112 d = 6.055454452393343e-006; |
---|
205 | 0113 <span class="keyword">end</span> |
---|
206 | 0114 |
---|
207 | 0115 |
---|
208 | 0116 <span class="comment">% Put together matrix of initial conditions</span> |
---|
209 | 0117 |
---|
210 | 0118 D = d*eye(4); |
---|
211 | 0119 <span class="comment">% First 8 columns for derivative</span> |
---|
212 | 0120 <span class="comment">% 9-th column is for closed orbit</span> |
---|
213 | 0121 <span class="comment">% R0 is the closed orbit</span> |
---|
214 | 0122 RM = [[R0 R0 R0 R0 R0 R0 R0 R0] + [D -D; zeros(2,8)],R0]; |
---|
215 | 0123 |
---|
216 | 0124 <span class="keyword">if</span> nargout < 2 |
---|
217 | 0125 <span class="comment">% Calculate M44 at the first element only. Use linepass</span> |
---|
218 | 0126 TMAT = linepass(LATTICE,RM); |
---|
219 | 0127 M44 = (TMAT(1:4,1:4)-TMAT(1:4,5:8))/(2*d); |
---|
220 | 0128 <span class="keyword">return</span> |
---|
221 | 0129 <span class="keyword">else</span> |
---|
222 | 0130 <span class="comment">% Calculate matrices at all REFPTS. Use linepass</span> |
---|
223 | 0131 <span class="comment">% Need to include the exit of the LATTICE to REFPTS array</span> |
---|
224 | 0132 <span class="keyword">if</span>(REFPTS(NR)~=NE+1) |
---|
225 | 0133 REFPTS = [REFPTS NE+1]; |
---|
226 | 0134 NR1 = NR+1; |
---|
227 | 0135 <span class="keyword">else</span> |
---|
228 | 0136 NR1 = NR; |
---|
229 | 0137 <span class="keyword">end</span> |
---|
230 | 0138 |
---|
231 | 0139 TMAT = linepass(LATTICE,RM,REFPTS); |
---|
232 | 0140 TMAT3 = reshape(TMAT(1:4,:),4,9,NR1); |
---|
233 | 0141 M44 = (TMAT3(1:4,1:4,NR1)-TMAT3(1:4,5:8,NR1))/(2*d); |
---|
234 | 0142 |
---|
235 | 0143 MSTACK = (TMAT3(:,1:4,1:NR)-TMAT3(:,5:8,1:NR))/(2*d); |
---|
236 | 0144 |
---|
237 | 0145 <span class="keyword">if</span> FULLFLAG |
---|
238 | 0146 S2 = [0 1;-1 0]; |
---|
239 | 0147 S4 = [S2, zeros(2);zeros(2),S2]; <span class="comment">% symplectic identity matrix</span> |
---|
240 | 0148 <span class="keyword">for</span> k =1:NR |
---|
241 | 0149 T = MSTACK(:,:,k); |
---|
242 | 0150 varargout{1}(:,:,k) = T*M44*S4'*T'*S4; |
---|
243 | 0151 <span class="keyword">end</span> |
---|
244 | 0152 <span class="keyword">else</span> |
---|
245 | 0153 varargout{1}=MSTACK; |
---|
246 | 0154 <span class="keyword">end</span> |
---|
247 | 0155 <span class="comment">% return the closed orbit if requested</span> |
---|
248 | 0156 <span class="keyword">if</span> nargout == 3 |
---|
249 | 0157 varargout{2}=squeeze(TMAT3(:,9,1:NR)); |
---|
250 | 0158 <span class="keyword">end</span> |
---|
251 | 0159 <span class="keyword">end</span></pre></div> |
---|
252 | <hr><address>Generated on Mon 21-May-2007 15:26:45 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
253 | </body> |
---|
254 | </html> |
---|