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 tunechrom</title> |
---|
6 | <meta name="keywords" content="tunechrom"> |
---|
7 | <meta name="description" content="TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED 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> > tunechrom.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>tunechrom |
---|
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>TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED 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 [tune, varargout] = tunechrom(RING,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">TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED lattice |
---|
31 | |
---|
32 | TUNE = TUNECHROM(RING,DP) - quick calculation of fractional part of the tune |
---|
33 | from numerically computed transfer matrix, assuming NO X-Y coupling. |
---|
34 | If the tune is above half-integer TUNECHROM finds 1/2 - nu |
---|
35 | |
---|
36 | TUNE = TUNECHROM(RING,DP,TUNEGUESS) - resolves the integer and half-integer |
---|
37 | uncertainty using the TUNEGUESS value. TUNEGUESS = [NUX,NUY] |
---|
38 | |
---|
39 | [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom',DDP) - optionally computes |
---|
40 | chromaticity by numerical differentiation from the difference between tune |
---|
41 | values at momentums DP+DDP and DP |
---|
42 | |
---|
43 | [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom') same as above, only uses |
---|
44 | for DDP the value set in global structure NUMDIFPARAMS. |
---|
45 | If NUMDIFPARAMS is not defined, TUNECHROM uses the internal default value for DDP (1e-8). |
---|
46 | |
---|
47 | TUNECHROM(..., 'coupling') - when 'coupling' switch is added to any of the above |
---|
48 | syntax options, the tunes and chromaticities are calculated assuming |
---|
49 | COUPLED lattice for two transverse eigenmodes. |
---|
50 | |
---|
51 | Note: TUNECHROM computes tunes and chromaticities from the 4-by-4 |
---|
52 | transfer matrix. The transfer matrix is found in FINDM44 using |
---|
53 | numerical differentiation. The error of numerical differentiation |
---|
54 | is sensitive to the step size. (Reference: Numerical Recipes) |
---|
55 | Calculation of tunes in TUNECHROM involves one numerical differentiation |
---|
56 | to find the 4-by-4 transfer matrix. |
---|
57 | Calculation of chromaticity in TUNECHROM involves TWO!!! numerical differentiations. |
---|
58 | The error in calculated chromaticity from may be substantial (~ 1e-5). |
---|
59 | Use the DDP argument to control the step size in chromaticity calculations |
---|
60 | Another way to control the step size is NUMDIFPARAMS structure |
---|
61 | |
---|
62 | |
---|
63 | See also <a href="linopt.html" class="code" title="function [LinData, varargout] = linopt(RING,DP,varargin);">LINOPT</a>, <a href="twissring.html" class="code" title="function [TD, varargout] = twissring(RING,DP,varargin);">TWISSRING</a>, <a href="twissline.html" class="code" title="function [TD, varargout] = twissline(LINE,DP,TWISSDATAIN,varargin);">TWISSLINE</a>, <a href="numdifparams.html" class="code" title="">NUMDIFPARAMS</a></pre></div> |
---|
64 | |
---|
65 | <!-- crossreference --> |
---|
66 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
67 | This function calls: |
---|
68 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
69 | <li><a href="findm44.html" class="code" title="function [M44, varargout] = findm44(LATTICE,DP,varargin)">findm44</a> FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice</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></ul> |
---|
70 | This function is called by: |
---|
71 | <ul style="list-style-image:url(../../matlabicon.gif)"> |
---|
72 | <li><a href="fitchrom2.html" class="code" title="function varargout = fitchrom2(newchrom, sextfam1, sextfam2, varargin)">fitchrom2</a> FITCHROM2 fits chromaticity of THERING using 2 sextupole families</li><li><a href="fittune2.html" class="code" title="function varargout = fittune2(newtunes, quadfam1, quadfam2, varargin);">fittune2</a> FITTUNE2 fits linear tunes of THERING using 2 quadrupole families</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></ul> |
---|
73 | <!-- crossreference --> |
---|
74 | |
---|
75 | |
---|
76 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2> |
---|
77 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [tune, varargout] = tunechrom(RING,DP,varargin)</a> |
---|
78 | 0002 <span class="comment">%TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED lattice</span> |
---|
79 | 0003 <span class="comment">%</span> |
---|
80 | 0004 <span class="comment">% TUNE = TUNECHROM(RING,DP) - quick calculation of fractional part of the tune</span> |
---|
81 | 0005 <span class="comment">% from numerically computed transfer matrix, assuming NO X-Y coupling.</span> |
---|
82 | 0006 <span class="comment">% If the tune is above half-integer TUNECHROM finds 1/2 - nu</span> |
---|
83 | 0007 <span class="comment">%</span> |
---|
84 | 0008 <span class="comment">% TUNE = TUNECHROM(RING,DP,TUNEGUESS) - resolves the integer and half-integer</span> |
---|
85 | 0009 <span class="comment">% uncertainty using the TUNEGUESS value. TUNEGUESS = [NUX,NUY]</span> |
---|
86 | 0010 <span class="comment">%</span> |
---|
87 | 0011 <span class="comment">% [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom',DDP) - optionally computes</span> |
---|
88 | 0012 <span class="comment">% chromaticity by numerical differentiation from the difference between tune</span> |
---|
89 | 0013 <span class="comment">% values at momentums DP+DDP and DP</span> |
---|
90 | 0014 <span class="comment">%</span> |
---|
91 | 0015 <span class="comment">% [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom') same as above, only uses</span> |
---|
92 | 0016 <span class="comment">% for DDP the value set in global structure NUMDIFPARAMS.</span> |
---|
93 | 0017 <span class="comment">% If NUMDIFPARAMS is not defined, TUNECHROM uses the internal default value for DDP (1e-8).</span> |
---|
94 | 0018 <span class="comment">%</span> |
---|
95 | 0019 <span class="comment">% TUNECHROM(..., 'coupling') - when 'coupling' switch is added to any of the above</span> |
---|
96 | 0020 <span class="comment">% syntax options, the tunes and chromaticities are calculated assuming</span> |
---|
97 | 0021 <span class="comment">% COUPLED lattice for two transverse eigenmodes.</span> |
---|
98 | 0022 <span class="comment">%</span> |
---|
99 | 0023 <span class="comment">% Note: TUNECHROM computes tunes and chromaticities from the 4-by-4</span> |
---|
100 | 0024 <span class="comment">% transfer matrix. The transfer matrix is found in FINDM44 using</span> |
---|
101 | 0025 <span class="comment">% numerical differentiation. The error of numerical differentiation</span> |
---|
102 | 0026 <span class="comment">% is sensitive to the step size. (Reference: Numerical Recipes)</span> |
---|
103 | 0027 <span class="comment">% Calculation of tunes in TUNECHROM involves one numerical differentiation</span> |
---|
104 | 0028 <span class="comment">% to find the 4-by-4 transfer matrix.</span> |
---|
105 | 0029 <span class="comment">% Calculation of chromaticity in TUNECHROM involves TWO!!! numerical differentiations.</span> |
---|
106 | 0030 <span class="comment">% The error in calculated chromaticity from may be substantial (~ 1e-5).</span> |
---|
107 | 0031 <span class="comment">% Use the DDP argument to control the step size in chromaticity calculations</span> |
---|
108 | 0032 <span class="comment">% Another way to control the step size is NUMDIFPARAMS structure</span> |
---|
109 | 0033 <span class="comment">%</span> |
---|
110 | 0034 <span class="comment">%</span> |
---|
111 | 0035 <span class="comment">% See also LINOPT, TWISSRING, TWISSLINE, NUMDIFPARAMS</span> |
---|
112 | 0036 |
---|
113 | 0037 DDP_default = 1e-8; |
---|
114 | 0038 |
---|
115 | 0039 <span class="comment">% Process input arguments</span> |
---|
116 | 0040 <span class="keyword">if</span> nargin>2 |
---|
117 | 0041 <span class="comment">% See if 'coupling' switch is thrown as the last argument</span> |
---|
118 | 0042 <span class="keyword">if</span> ischar(varargin{end}) & strncmp(lower(varargin{end}),<span class="string">'coupl'</span>,5) |
---|
119 | 0043 COUPLINGFLAG = 1; |
---|
120 | 0044 <span class="keyword">else</span> |
---|
121 | 0045 COUPLINGFLAG = 0; |
---|
122 | 0046 <span class="keyword">end</span> |
---|
123 | 0047 <span class="comment">% See if TUNEGUESS is specified as the third argument</span> |
---|
124 | 0048 <span class="keyword">if</span> isnumeric(varargin{1}) & length(varargin{1})==2 |
---|
125 | 0049 TUNEGUESSFLAG = 1; |
---|
126 | 0050 TUNEGUESS = varargin{1}; |
---|
127 | 0051 <span class="keyword">else</span> |
---|
128 | 0052 TUNEGUESSFLAG = 0; |
---|
129 | 0053 TUNEGUESS = [0.25, 0.25]; <span class="comment">% if no TUNEGUESS is specified</span> |
---|
130 | 0054 <span class="keyword">end</span> |
---|
131 | 0055 <span class="comment">% See if any of the argument is 'chrom' ,then chech if the argument after 'chrom' is DDP</span> |
---|
132 | 0056 CHROMFLAG = 0; |
---|
133 | 0057 <span class="keyword">for</span> i = 1:nargin-2 |
---|
134 | 0058 <span class="keyword">if</span> strcmp(lower(varargin{i}),<span class="string">'chrom'</span>) |
---|
135 | 0059 CHROMFLAG = 1; |
---|
136 | 0060 <span class="keyword">if</span> i<nargin-2 & isnumeric(varargin{i+1}) |
---|
137 | 0061 DDP = varargin{i+1}; |
---|
138 | 0062 <span class="keyword">else</span> |
---|
139 | 0063 <span class="comment">% Check if NUMDIFPARAMS is defined globally</span> |
---|
140 | 0064 <span class="keyword">global</span> NUMDIFPARAMS |
---|
141 | 0065 <span class="keyword">if</span> isfield(NUMDIFPARAMS,<span class="string">'DPStep'</span>) |
---|
142 | 0066 DDP = NUMDIFPARAMS.DPStep; |
---|
143 | 0067 <span class="keyword">else</span> <span class="comment">% use default DDP</span> |
---|
144 | 0068 DDP = DDP_default; |
---|
145 | 0069 <span class="keyword">end</span> |
---|
146 | 0070 <span class="keyword">end</span> |
---|
147 | 0071 <span class="keyword">break</span> |
---|
148 | 0072 <span class="keyword">end</span> |
---|
149 | 0073 <span class="keyword">end</span> |
---|
150 | 0074 |
---|
151 | 0075 |
---|
152 | 0076 <span class="keyword">else</span> |
---|
153 | 0077 COUPLINGFLAG = 0; |
---|
154 | 0078 CHROMFLAG = 0; |
---|
155 | 0079 TUNEGUESSFLAG = 0; |
---|
156 | 0080 TUNEGUESS = [0.25, 0.25]; <span class="comment">% if no TUNEGUESS is specified</span> |
---|
157 | 0081 <span class="keyword">end</span> |
---|
158 | 0082 |
---|
159 | 0083 M44 = <a href="findm44.html" class="code" title="function [M44, varargout] = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP); |
---|
160 | 0084 |
---|
161 | 0085 <span class="keyword">if</span> COUPLINGFLAG |
---|
162 | 0086 M =M44(1:2,1:2); |
---|
163 | 0087 N =M44(3:4,3:4); |
---|
164 | 0088 m =M44(1:2,3:4); |
---|
165 | 0089 n =M44(3:4,1:2); |
---|
166 | 0090 |
---|
167 | 0091 <span class="comment">% 2-by-2 symplectic matrix</span> |
---|
168 | 0092 S = [0 1; -1 0]; |
---|
169 | 0093 H = m + S*n'*S'; |
---|
170 | 0094 t = trace(M-N); |
---|
171 | 0095 |
---|
172 | 0096 g = sqrt(1 + sqrt(t*t/(t*t+4*det(H))))/sqrt(2); |
---|
173 | 0097 G = diag([g g]); |
---|
174 | 0098 C = -H*sign(t)/(g*sqrt(t*t+4*det(H))); |
---|
175 | 0099 A = G*G*M - G*(m*S*C'*S' + C*n) + C*N*S*C'*S'; |
---|
176 | 0100 B = G*G*N + G*(S*C'*S'*m + n*C) + S*C'*S'*M*C; |
---|
177 | 0101 |
---|
178 | 0102 cos_mu_x = trace(A)/2; |
---|
179 | 0103 cos_mu_y = trace(B)/2; |
---|
180 | 0104 |
---|
181 | 0105 sin_mu_x = sign(A(1,2))*sqrt(-A(1,2)*A(2,1)-(A(1,1)-A(2,2))^2/4); |
---|
182 | 0106 sin_mu_y = sign(B(1,2))*sqrt(-B(1,2)*B(2,1)-(B(1,1)-B(2,2))^2/4); |
---|
183 | 0107 |
---|
184 | 0108 <span class="keyword">else</span> |
---|
185 | 0109 cos_mu_x = (M44(1,1)+M44(2,2))/2; |
---|
186 | 0110 cos_mu_y = (M44(3,3)+M44(4,4))/2; |
---|
187 | 0111 <span class="keyword">end</span> |
---|
188 | 0112 TUNE = acos([cos_mu_x,cos_mu_y])/2/pi; |
---|
189 | 0113 |
---|
190 | 0114 |
---|
191 | 0115 <span class="keyword">if</span> TUNEGUESSFLAG |
---|
192 | 0116 <span class="comment">% Check if the TUNE is in the same quadrant as TUNEGUESS</span> |
---|
193 | 0117 guess_quadrant = (TUNEGUESS-floor(TUNEGUESS))> 1/2; |
---|
194 | 0118 tune = floor(TUNEGUESS) + guess_quadrant + TUNE.*(sign(1/2 - guess_quadrant)); |
---|
195 | 0119 <span class="keyword">else</span> |
---|
196 | 0120 tune = TUNE; |
---|
197 | 0121 <span class="keyword">end</span> |
---|
198 | 0122 |
---|
199 | 0123 <span class="keyword">if</span> CHROMFLAG & nargout > 1 |
---|
200 | 0124 <span class="keyword">if</span> COUPLINGFLAG |
---|
201 | 0125 tune_DDP = <a href="tunechrom.html" class="code" title="function [tune, varargout] = tunechrom(RING,DP,varargin)">tunechrom</a>(RING,DP+DDP,TUNEGUESS,<span class="string">'coupling'</span>); |
---|
202 | 0126 <span class="keyword">else</span> |
---|
203 | 0127 tune_DDP = <a href="tunechrom.html" class="code" title="function [tune, varargout] = tunechrom(RING,DP,varargin)">tunechrom</a>(RING,DP+DDP,TUNEGUESS); |
---|
204 | 0128 <span class="keyword">end</span> |
---|
205 | 0129 varargout{1} = (tune_DDP - tune)/DDP; |
---|
206 | 0130 <span class="keyword">end</span></pre></div> |
---|
207 | <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> |
---|
208 | </body> |
---|
209 | </html> |
---|