source: MML/trunk/at/doc_html/at/atphysics/findm44.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: 14.8 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 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 &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; findm44.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>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>
83This 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>
86This 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>
940002 <span class="comment">%FINDM44 numerically finds the 4x4 transfer matrix of an accelerator lattice</span>
950003 <span class="comment">% for a particle with relative momentum deviation DP</span>
960004 <span class="comment">%</span>
970005 <span class="comment">% IMPORTANT!!! FINDM44 assumes constant momentum deviation.</span>
980006 <span class="comment">%   PassMethod used for any element in the LATTICE SHOULD NOT</span>
990007 <span class="comment">%   1.change the longitudinal momentum dP</span>
1000008 <span class="comment">%     (cavities , magnets with radiation, ...)</span>
1010009 <span class="comment">%   2.have any time dependence (localized impedance, fast kickers, ...)</span>
1020010 <span class="comment">%</span>
1030011 <span class="comment">% M44 = FINDM44(LATTICE,DP) finds a full one-turn</span>
1040012 <span class="comment">%    matrix at the entrance of the first element</span>
1050013 <span class="comment">%    !!! With this syntax FINDM44 assumes that the LATTICE</span>
1060014 <span class="comment">%    is a ring and first finds the closed orbit</span>
1070015 <span class="comment">%</span>
1080016 <span class="comment">% [M44,T] = FINDM44(LATTICE,DP,REFPTS) also returns</span>
1090017 <span class="comment">%    4-by-4 transfer matrixes  between entrance of</span>
1100018 <span class="comment">%    the first element and each element indexed by REFPTS.</span>
1110019 <span class="comment">%    T is 4-by-4-by-length(REFPTS) 3 dimensional array</span>
1120020 <span class="comment">%    so that the set of indexes (:,:,i) selects the 4-by-4</span>
1130021 <span class="comment">%    matrix at the i-th reference point.</span>
1140022 <span class="comment">%</span>
1150023 <span class="comment">%    Note: REFPTS is an array of increasing indexes that</span>
1160024 <span class="comment">%    select elements from range 1 to length(LATTICE)+1.</span>
1170025 <span class="comment">%    See further explanation of REFPTS in the 'help' for FINDSPOS</span>
1180026 <span class="comment">%    When REFPTS= [ 1 2 .. ] the first point is the entrance of the</span>
1190027 <span class="comment">%    first element and T(:,:,1) - identity matrix</span>
1200028 <span class="comment">%</span>
1210029 <span class="comment">%    Note: REFPTS is allowed to go 1 point beyond the</span>
1220030 <span class="comment">%    number of elements. In this case the last point is</span>
1230031 <span class="comment">%    the EXIT of the last element. If LATTICE is a RING</span>
1240032 <span class="comment">%    it is also the entrance of the first element</span>
1250033 <span class="comment">%    after 1 turn: T(:,:,end) = M</span>
1260034 <span class="comment">%</span>
1270035 <span class="comment">% [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN) - Does not search for</span>
1280036 <span class="comment">%   closed orbit. Instead the ORBITIN,a 1-by-6 vector of initial</span>
1290037 <span class="comment">%   conditions is used: [x0, px0, y0, py0, DP, 0]' where</span>
1300038 <span class="comment">%   the same DP as argument 2. The sixth component is ignored.</span>
1310039 <span class="comment">%   This syntax is useful to specify the entrance orbit</span>
1320040 <span class="comment">%   if LATTICE is not a ring or to avoid recomputing the</span>
1330041 <span class="comment">%   closed orbit if is already known.</span>
1340042 <span class="comment">%</span>
1350043 <span class="comment">% [M44, T] = FINDM44(LATTICE,DP,REFPTS,ORBITIN,'full') - same as above except</span>
1360044 <span class="comment">%    matrixes returned in T are full 1-turn matrixes at the entrance of each</span>
1370045 <span class="comment">%    element indexed by REFPTS.</span>
1380046 <span class="comment">%</span>
1390047 <span class="comment">% [M44, T, orbit] = FINDM44(...) in addition returns</span>
1400048 <span class="comment">%    at REFPTS the closed orbit calculated along the</span>
1410049 <span class="comment">%    way with findorbit4</span>
1420050 <span class="comment">%</span>
1430051 <span class="comment">% See also LINEPASS, LATTICEPASS, FINDORBIT4, FINDSPOS</span>
1440052
1450053 <span class="comment">% *************************************************************************</span>
1460054 <span class="comment">%   The numerical differentiation in FINDM44 uses symmetric form</span>
1470055 <span class="comment">%</span>
1480056 <span class="comment">%         F(x+delta) - F(x-delta)</span>
1490057 <span class="comment">%       --------------------------------------</span>
1500058 <span class="comment">%              2*delta</span>
1510059 <span class="comment">%</span>
1520060 <span class="comment">%    with optimal differentiation step delta given by !!!! DO LATER</span>
1530061 <span class="comment">%    The relative error in the derivative computed this way</span>
1540062 <span class="comment">%    is !!!!!!!!!!!!!!!!! DO LATER</span>
1550063 <span class="comment">%    Reference: Numerical Recipes.</span>
1560064
1570065
1580066 <span class="keyword">if</span> ~iscell(LATTICE)
1590067     error(<span class="string">'First argument must be a cell array'</span>);
1600068 <span class="keyword">end</span>
1610069
1620070 NE = length(LATTICE);
1630071
1640072
1650073 <span class="keyword">switch</span> nargin
1660074     <span class="keyword">case</span> 5 <span class="comment">% FINDM44(LATTICE,DP,REFPTS,ORBITIN,'full')</span>
1670075         <span class="keyword">if</span>(lower(varargin{3})==<span class="string">'full'</span>)
1680076             FULLFLAG = 1;
1690077             REFPTS = varargin{1};
1700078             R0 = varargin{2};
1710079             R0(5) = DP;
1720080             R0(6)= 0;
1730081         <span class="keyword">else</span>
1740082             error(<span class="string">'Fifth argument - unknown option'</span>)
1750083         <span class="keyword">end</span>
1760084     <span class="keyword">case</span> 4 <span class="comment">% FINDM44(LATTICE,DP,REFPTS,ORBITIN)</span>
1770085         FULLFLAG = 0;
1780086         REFPTS = varargin{1};
1790087         R0 = varargin{2};
1800088         R0(5) = DP;
1810089         R0(6)= 0;
1820090     <span class="keyword">case</span> 3 <span class="comment">% FINDM44(LATTICE,DP,REFPTS)</span>
1830091         FULLFLAG = 0;
1840092         REFPTS = varargin{1};
1850093         R0 = [<a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">findorbit4</a>(LATTICE,DP);DP;0];
1860094     <span class="keyword">case</span> 2 <span class="comment">% FINDM44(LATTICE,DP)</span>
1870095         REFPTS = NE+1;
1880096         FULLFLAG = 0;
1890097         R0 = [<a href="findorbit4.html" class="code" title="function orbit = findorbit4(RING,dP,varargin);">findorbit4</a>(LATTICE,DP);DP;0];
1900098     <span class="keyword">otherwise</span>
1910099         error(<span class="string">'Incorrect number of input arguments'</span>);
1920100 <span class="keyword">end</span>
1930101
1940102 NR = length(REFPTS);
1950103
1960104
1970105 <span class="comment">% Determine step size to use for numerical differentiation</span>
1980106 <span class="keyword">global</span> NUMDIFPARAMS
1990107
2000108 <span class="keyword">if</span> isfield(NUMDIFPARAMS,<span class="string">'XYStep'</span>)
2010109     d = NUMDIFPARAMS.XYStep';
2020110 <span class="keyword">else</span>
2030111     <span class="comment">% optimal differentiation step - Numerical Recipes</span>
2040112     d =  6.055454452393343e-006;
2050113 <span class="keyword">end</span>
2060114
2070115
2080116 <span class="comment">% Put together matrix of initial conditions</span>
2090117
2100118 D = d*eye(4);
2110119 <span class="comment">% First 8 columns for derivative</span>
2120120 <span class="comment">% 9-th column is for closed orbit</span>
2130121 <span class="comment">% R0 is the closed orbit</span>
2140122 RM = [[R0 R0 R0 R0 R0 R0 R0 R0] + [D -D; zeros(2,8)],R0];
2150123
2160124 <span class="keyword">if</span> nargout &lt; 2
2170125     <span class="comment">% Calculate M44 at the first element only. Use linepass</span>
2180126     TMAT = linepass(LATTICE,RM);
2190127     M44 = (TMAT(1:4,1:4)-TMAT(1:4,5:8))/(2*d);
2200128     <span class="keyword">return</span>
2210129 <span class="keyword">else</span>
2220130     <span class="comment">% Calculate matrices at all REFPTS. Use linepass</span>
2230131     <span class="comment">% Need to include the exit of the LATTICE to REFPTS array</span>
2240132     <span class="keyword">if</span>(REFPTS(NR)~=NE+1)
2250133         REFPTS = [REFPTS NE+1];
2260134         NR1 = NR+1;
2270135     <span class="keyword">else</span>
2280136         NR1 = NR;
2290137     <span class="keyword">end</span>
2300138
2310139     TMAT  = linepass(LATTICE,RM,REFPTS);
2320140     TMAT3 = reshape(TMAT(1:4,:),4,9,NR1);
2330141     M44   = (TMAT3(1:4,1:4,NR1)-TMAT3(1:4,5:8,NR1))/(2*d);
2340142
2350143     MSTACK = (TMAT3(:,1:4,1:NR)-TMAT3(:,5:8,1:NR))/(2*d);
2360144
2370145     <span class="keyword">if</span> FULLFLAG
2380146         S2 = [0 1;-1 0];
2390147         S4 = [S2, zeros(2);zeros(2),S2]; <span class="comment">% symplectic identity matrix</span>
2400148         <span class="keyword">for</span> k =1:NR
2410149             T =  MSTACK(:,:,k);
2420150             varargout{1}(:,:,k) = T*M44*S4'*T'*S4;
2430151         <span class="keyword">end</span>
2440152     <span class="keyword">else</span>
2450153         varargout{1}=MSTACK;
2460154     <span class="keyword">end</span>
2470155     <span class="comment">% return the closed orbit if requested</span>
2480156     <span class="keyword">if</span> nargout == 3
2490157         varargout{2}=squeeze(TMAT3(:,9,1:NR));
2500158     <span class="keyword">end</span>
2510159 <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> &copy; 2003</address>
253</body>
254</html>
Note: See TracBrowser for help on using the repository browser.