source: MML/trunk/at/doc_html/at/atphysics/tunechrom.html @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 13.2 KB
Line 
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 &copy; 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> &gt;  <a href="../index.html">at</a> &gt; <a href="index.html">atphysics</a> &gt; tunechrom.m</div>
16
17<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
18<td align="right"><a href="index.html">Index for at/atphysics&nbsp;<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>
67This 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>
70This 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>
780002 <span class="comment">%TUNECHROM computes linear tunes and chromaticities for COUPLED or UNCOUPLED lattice</span>
790003 <span class="comment">%</span>
800004 <span class="comment">% TUNE = TUNECHROM(RING,DP) - quick calculation of fractional part of the tune</span>
810005 <span class="comment">%    from numerically computed transfer matrix, assuming NO X-Y coupling.</span>
820006 <span class="comment">%    If the tune is above half-integer TUNECHROM finds 1/2 - nu</span>
830007 <span class="comment">%</span>
840008 <span class="comment">% TUNE = TUNECHROM(RING,DP,TUNEGUESS) - resolves the integer and half-integer</span>
850009 <span class="comment">%    uncertainty using the TUNEGUESS value. TUNEGUESS = [NUX,NUY]</span>
860010 <span class="comment">%</span>
870011 <span class="comment">% [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom',DDP) - optionally computes</span>
880012 <span class="comment">%    chromaticity by numerical differentiation from the difference between tune</span>
890013 <span class="comment">%    values at momentums DP+DDP and DP</span>
900014 <span class="comment">%</span>
910015 <span class="comment">% [TUNE, CHROM] = TUNECHROM(RINGD,DP,TUNEGUESS,'chrom') same as above, only uses</span>
920016 <span class="comment">%    for DDP the value set in global structure NUMDIFPARAMS.</span>
930017 <span class="comment">%    If NUMDIFPARAMS is not defined, TUNECHROM uses the internal default value for DDP (1e-8).</span>
940018 <span class="comment">%</span>
950019 <span class="comment">% TUNECHROM(..., 'coupling') - when 'coupling' switch is added to any of the above</span>
960020 <span class="comment">%    syntax options, the tunes and chromaticities are calculated assuming</span>
970021 <span class="comment">%    COUPLED lattice for two transverse eigenmodes.</span>
980022 <span class="comment">%</span>
990023 <span class="comment">% Note: TUNECHROM computes tunes and chromaticities from the 4-by-4</span>
1000024 <span class="comment">%   transfer matrix. The transfer matrix is found in FINDM44 using</span>
1010025 <span class="comment">%   numerical differentiation. The error of numerical differentiation</span>
1020026 <span class="comment">%   is sensitive to the step size. (Reference: Numerical Recipes)</span>
1030027 <span class="comment">%   Calculation of tunes in TUNECHROM involves one numerical differentiation</span>
1040028 <span class="comment">%   to find the 4-by-4 transfer matrix.</span>
1050029 <span class="comment">%   Calculation of chromaticity in TUNECHROM involves TWO!!! numerical differentiations.</span>
1060030 <span class="comment">%   The error in calculated chromaticity from may be substantial (~ 1e-5).</span>
1070031 <span class="comment">%   Use the DDP argument to control the step size in chromaticity calculations</span>
1080032 <span class="comment">%   Another  way to control the step size is NUMDIFPARAMS structure</span>
1090033 <span class="comment">%</span>
1100034 <span class="comment">%</span>
1110035 <span class="comment">% See also LINOPT, TWISSRING, TWISSLINE, NUMDIFPARAMS</span>
1120036
1130037 DDP_default = 1e-8;
1140038
1150039 <span class="comment">% Process input arguments</span>
1160040 <span class="keyword">if</span> nargin&gt;2
1170041     <span class="comment">% See if 'coupling' switch is thrown as the last argument</span>
1180042     <span class="keyword">if</span> ischar(varargin{end}) &amp; strncmp(lower(varargin{end}),<span class="string">'coupl'</span>,5)
1190043         COUPLINGFLAG  = 1;
1200044     <span class="keyword">else</span>
1210045         COUPLINGFLAG  = 0;
1220046     <span class="keyword">end</span>
1230047     <span class="comment">% See if TUNEGUESS is specified as the third argument</span>
1240048     <span class="keyword">if</span> isnumeric(varargin{1}) &amp; length(varargin{1})==2
1250049         TUNEGUESSFLAG = 1;
1260050         TUNEGUESS = varargin{1};
1270051     <span class="keyword">else</span>
1280052         TUNEGUESSFLAG = 0;
1290053         TUNEGUESS = [0.25, 0.25]; <span class="comment">% if no TUNEGUESS is specified</span>
1300054     <span class="keyword">end</span>
1310055     <span class="comment">% See if any of the argument is 'chrom' ,then chech if the argument after 'chrom' is DDP</span>
1320056     CHROMFLAG = 0;
1330057     <span class="keyword">for</span> i = 1:nargin-2
1340058        <span class="keyword">if</span> strcmp(lower(varargin{i}),<span class="string">'chrom'</span>)
1350059             CHROMFLAG = 1;
1360060             <span class="keyword">if</span> i&lt;nargin-2 &amp; isnumeric(varargin{i+1})
1370061                 DDP = varargin{i+1};
1380062             <span class="keyword">else</span>
1390063                 <span class="comment">% Check if NUMDIFPARAMS is defined globally</span>
1400064                 <span class="keyword">global</span> NUMDIFPARAMS
1410065                 <span class="keyword">if</span> isfield(NUMDIFPARAMS,<span class="string">'DPStep'</span>)
1420066                     DDP = NUMDIFPARAMS.DPStep;
1430067                 <span class="keyword">else</span> <span class="comment">% use default DDP</span>
1440068                     DDP =  DDP_default;
1450069                 <span class="keyword">end</span>           
1460070             <span class="keyword">end</span>
1470071             <span class="keyword">break</span>
1480072         <span class="keyword">end</span>
1490073     <span class="keyword">end</span>
1500074             
1510075     
1520076 <span class="keyword">else</span>
1530077     COUPLINGFLAG = 0;
1540078     CHROMFLAG = 0;
1550079     TUNEGUESSFLAG = 0;
1560080     TUNEGUESS = [0.25, 0.25]; <span class="comment">% if no TUNEGUESS is specified</span>
1570081 <span class="keyword">end</span>
1580082
1590083 M44 = <a href="findm44.html" class="code" title="function [M44, varargout]  = findm44(LATTICE,DP,varargin)">findm44</a>(RING,DP);
1600084
1610085 <span class="keyword">if</span> COUPLINGFLAG
1620086     M =M44(1:2,1:2);
1630087     N =M44(3:4,3:4);
1640088     m =M44(1:2,3:4);
1650089     n =M44(3:4,1:2);
1660090
1670091     <span class="comment">% 2-by-2 symplectic matrix</span>
1680092     S = [0 1; -1 0];
1690093     H = m + S*n'*S';
1700094     t = trace(M-N);
1710095
1720096     g = sqrt(1 + sqrt(t*t/(t*t+4*det(H))))/sqrt(2);
1730097     G = diag([g g]);
1740098     C = -H*sign(t)/(g*sqrt(t*t+4*det(H)));
1750099     A = G*G*M  -  G*(m*S*C'*S' + C*n) + C*N*S*C'*S';
1760100     B = G*G*N  +  G*(S*C'*S'*m + n*C) + S*C'*S'*M*C;
1770101     
1780102     cos_mu_x = trace(A)/2;
1790103     cos_mu_y = trace(B)/2;
1800104     
1810105     sin_mu_x = sign(A(1,2))*sqrt(-A(1,2)*A(2,1)-(A(1,1)-A(2,2))^2/4);
1820106     sin_mu_y = sign(B(1,2))*sqrt(-B(1,2)*B(2,1)-(B(1,1)-B(2,2))^2/4);
1830107     
1840108 <span class="keyword">else</span>
1850109     cos_mu_x = (M44(1,1)+M44(2,2))/2;
1860110     cos_mu_y = (M44(3,3)+M44(4,4))/2;   
1870111 <span class="keyword">end</span>
1880112 TUNE = acos([cos_mu_x,cos_mu_y])/2/pi;
1890113
1900114
1910115 <span class="keyword">if</span> TUNEGUESSFLAG
1920116     <span class="comment">% Check if the TUNE is in the same quadrant as TUNEGUESS</span>
1930117     guess_quadrant = (TUNEGUESS-floor(TUNEGUESS))&gt; 1/2;
1940118     tune = floor(TUNEGUESS) +  guess_quadrant + TUNE.*(sign(1/2 - guess_quadrant));
1950119 <span class="keyword">else</span>
1960120     tune = TUNE;
1970121 <span class="keyword">end</span>
1980122
1990123 <span class="keyword">if</span> CHROMFLAG &amp; nargout &gt; 1 
2000124     <span class="keyword">if</span> COUPLINGFLAG
2010125         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>);
2020126     <span class="keyword">else</span>
2030127         tune_DDP = <a href="tunechrom.html" class="code" title="function [tune, varargout] = tunechrom(RING,DP,varargin)">tunechrom</a>(RING,DP+DDP,TUNEGUESS);
2040128     <span class="keyword">end</span>
2050129     varargout{1} = (tune_DDP - tune)/DDP;
2060130 <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> &copy; 2003</address>
208</body>
209</html>
Note: See TracBrowser for help on using the repository browser.