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 steptune</title> |
---|
6 | <meta name="keywords" content="steptune"> |
---|
7 | <meta name="description" content="STEPTUNE - Step the tune"> |
---|
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">mml</a> > steptune.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 mml <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>steptune |
---|
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>STEPTUNE - Step the tune</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 [DelQuad, ActuatorFamily] = steptune(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">STEPTUNE - Step the tune |
---|
31 | [DelQuad, QuadFamily] = steptune(DeltaTune, TuneResponseMatrix); |
---|
32 | |
---|
33 | Step change in storage ring tune using the default tune correctors (findmemberof('Tune Corrector'))</pre></div> |
---|
34 | |
---|
35 | <!-- crossreference --> |
---|
36 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
37 | This function calls: |
---|
38 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
39 | <li><a href="findmemberof.html" class="code" title="function FamilyName = findmemberof(MemberString, Field)">findmemberof</a> FINDMEMBEROF - Finds all family members</li><li><a href="getsp.html" class="code" title="function [SP, tout, DataTime, ErrorFlag] = getsp(Family, varargin)">getsp</a> GETSP - Gets setpoint channels</li><li><a href="gettuneresp.html" class="code" title="function [TuneMatrix, FileName] = gettuneresp(varargin)">gettuneresp</a> GETTUNERESP - Loads the tune response vector (or matrix) for multiple quadrupole families</li><li><a href="setsp.html" class="code" title="function ErrorFlag = setsp(Family, varargin)">setsp</a> SETSP - Makes an absolute setpoint change to the 'Setpoint' field</li></ul> |
---|
40 | This function is called by: |
---|
41 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
42 | <li><a href="settune.html" class="code" title="function [DelQuad, ActuatorFamily] = settune(varargin)">settune</a> SETTUNE - Set the tune</li></ul> |
---|
43 | <!-- crossreference --> |
---|
44 | |
---|
45 | |
---|
46 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
47 | <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [DelQuad, ActuatorFamily] = steptune(varargin)</a> |
---|
48 | 0002 <span class="comment">%STEPTUNE - Step the tune</span> |
---|
49 | 0003 <span class="comment">% [DelQuad, QuadFamily] = steptune(DeltaTune, TuneResponseMatrix);</span> |
---|
50 | 0004 <span class="comment">%</span> |
---|
51 | 0005 <span class="comment">% Step change in storage ring tune using the default tune correctors (findmemberof('Tune Corrector'))</span> |
---|
52 | 0006 |
---|
53 | 0007 <span class="comment">% INPUTS</span> |
---|
54 | 0008 <span class="comment">% 1. | Change in Horizontal Tune |</span> |
---|
55 | 0009 <span class="comment">% DeltaTune = | |</span> |
---|
56 | 0010 <span class="comment">% | Change in Vertical Tune |</span> |
---|
57 | 0011 <span class="comment">% 2. TuneResponseMatrix - Tune response matrix {Default: findmemberof('Tune Corrector')}</span> |
---|
58 | 0012 <span class="comment">% 3. ActuatorFamily - Quadrupole to vary, ex {'Q7', 'Q9'} {Default: findmemberof('Tune Corrector')}</span> |
---|
59 | 0013 <span class="comment">% 4. Optional override of the units:</span> |
---|
60 | 0014 <span class="comment">% 'Physics' - Use physics units</span> |
---|
61 | 0015 <span class="comment">% 'Hardware' - Use hardware units</span> |
---|
62 | 0016 <span class="comment">% 5. Optional override of the mode:</span> |
---|
63 | 0017 <span class="comment">% 'Online' - Set/Get data online</span> |
---|
64 | 0018 <span class="comment">% 'Model' - Set/Get data on the simulated accelerator using AT</span> |
---|
65 | 0019 <span class="comment">% 'Simulator' - Set/Get data on the simulated accelerator using AT</span> |
---|
66 | 0020 <span class="comment">% 'Manual' - Set/Get data manually</span> |
---|
67 | 0021 <span class="comment">%</span> |
---|
68 | 0022 <span class="comment">%</span> |
---|
69 | 0023 <span class="comment">% OUTPUTS</span> |
---|
70 | 0024 <span class="comment">% 1. DelQuad</span> |
---|
71 | 0025 <span class="comment">% 2. QuadFamily - Families used (cell array)</span> |
---|
72 | 0026 <span class="comment">%</span> |
---|
73 | 0027 <span class="comment">% ALGORITHM</span> |
---|
74 | 0028 <span class="comment">% SVD method</span> |
---|
75 | 0029 <span class="comment">% DelQuad = inv(TuneResponseMatrix) * DeltaTune</span> |
---|
76 | 0030 |
---|
77 | 0031 <span class="comment">%</span> |
---|
78 | 0032 <span class="comment">% Written by Gregory J. Portmann</span> |
---|
79 | 0033 <span class="comment">% Modified by Laurent S. Nadolski</span> |
---|
80 | 0034 <span class="comment">% 06/01/06 - Introduction of ActuatorFamily as a input</span> |
---|
81 | 0035 |
---|
82 | 0036 <span class="comment">% Initialize</span> |
---|
83 | 0037 |
---|
84 | 0038 UnitsFlag = {}; |
---|
85 | 0039 ModeFlag = {}; |
---|
86 | 0040 <span class="keyword">for</span> i = length(varargin):-1:1 |
---|
87 | 0041 <span class="keyword">if</span> strcmpi(varargin{i},<span class="string">'physics'</span>) |
---|
88 | 0042 UnitsFlag = varargin(i); |
---|
89 | 0043 varargin(i) = []; |
---|
90 | 0044 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'hardware'</span>) |
---|
91 | 0045 UnitsFlag = varargin(i); |
---|
92 | 0046 varargin(i) = []; |
---|
93 | 0047 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'Simulator'</span>) | strcmpi(varargin{i},<span class="string">'Model'</span>) |
---|
94 | 0048 ModeFlag = varargin(i); |
---|
95 | 0049 varargin(i) = []; |
---|
96 | 0050 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'online'</span>) |
---|
97 | 0051 ModeFlag = varargin(i); |
---|
98 | 0052 varargin(i) = []; |
---|
99 | 0053 <span class="keyword">elseif</span> strcmpi(varargin{i},<span class="string">'manual'</span>) |
---|
100 | 0054 ModeFlag = varargin(i); |
---|
101 | 0055 varargin(i) = []; |
---|
102 | 0056 <span class="keyword">end</span> |
---|
103 | 0057 <span class="keyword">end</span> |
---|
104 | 0058 |
---|
105 | 0059 <span class="keyword">if</span> length(varargin) >= 1 |
---|
106 | 0060 DeltaTune = varargin{1}; |
---|
107 | 0061 <span class="keyword">else</span> |
---|
108 | 0062 DeltaTune = []; |
---|
109 | 0063 <span class="keyword">end</span> |
---|
110 | 0064 <span class="keyword">if</span> isempty(DeltaTune) |
---|
111 | 0065 answer = inputdlg({<span class="string">'Change the horizontal tune by'</span>, <span class="string">'Change the vertical tune by'</span>},<span class="string">'STEPTUNE'</span>,1,{<span class="string">'0'</span>,<span class="string">'0'</span>}); |
---|
112 | 0066 <span class="keyword">if</span> isempty(answer) |
---|
113 | 0067 <span class="keyword">return</span> |
---|
114 | 0068 <span class="keyword">end</span> |
---|
115 | 0069 DeltaTune(1,1) = str2num(answer{1}); |
---|
116 | 0070 DeltaTune(2,1) = str2num(answer{2}); |
---|
117 | 0071 <span class="keyword">end</span> |
---|
118 | 0072 |
---|
119 | 0073 DeltaTune = DeltaTune(:); |
---|
120 | 0074 <span class="keyword">if</span> size(DeltaTune,1) ~= 2 |
---|
121 | 0075 error(<span class="string">'Input must be a 2x1 column vector.'</span>); |
---|
122 | 0076 <span class="keyword">end</span> |
---|
123 | 0077 <span class="keyword">if</span> DeltaTune(1)==0 && DeltaTune(2)==0 |
---|
124 | 0078 <span class="keyword">return</span> |
---|
125 | 0079 <span class="keyword">end</span> |
---|
126 | 0080 |
---|
127 | 0081 <span class="keyword">if</span> length(varargin) >= 2 |
---|
128 | 0082 TuneResponseMatrix = varargin{2}; |
---|
129 | 0083 <span class="keyword">else</span> |
---|
130 | 0084 TuneResponseMatrix = []; |
---|
131 | 0085 <span class="keyword">end</span> |
---|
132 | 0086 <span class="keyword">if</span> isempty(TuneResponseMatrix) |
---|
133 | 0087 TuneResponseMatrix = <a href="gettuneresp.html" class="code" title="function [TuneMatrix, FileName] = gettuneresp(varargin)">gettuneresp</a>(UnitsFlag{:}); |
---|
134 | 0088 <span class="keyword">end</span> |
---|
135 | 0089 <span class="keyword">if</span> isempty(TuneResponseMatrix) |
---|
136 | 0090 error(<span class="string">'The tune response matrix must be an input or available in one of the default response matrix files.'</span>); |
---|
137 | 0091 <span class="keyword">end</span> |
---|
138 | 0092 |
---|
139 | 0093 <span class="comment">% User ActuatorFamily</span> |
---|
140 | 0094 <span class="keyword">if</span> length(varargin) >= 3 |
---|
141 | 0095 ActuatorFamily = varargin{3}; |
---|
142 | 0096 <span class="keyword">else</span> |
---|
143 | 0097 ActuatorFamily = <a href="findmemberof.html" class="code" title="function FamilyName = findmemberof(MemberString, Field)">findmemberof</a>(<span class="string">'Tune Corrector'</span>)'; |
---|
144 | 0098 <span class="keyword">if</span> isempty(ActuatorFamily) |
---|
145 | 0099 ActuatorFamily = {<span class="string">'QF'</span>,<span class="string">'QD'</span>}; |
---|
146 | 0100 <span class="keyword">end</span> |
---|
147 | 0101 <span class="keyword">end</span> |
---|
148 | 0102 |
---|
149 | 0103 <span class="comment">% It's probably wise to check the .Units fields</span> |
---|
150 | 0104 |
---|
151 | 0105 <span class="comment">% 1. SVD Tune Correction</span> |
---|
152 | 0106 <span class="comment">% Decompose the tune response matrix:</span> |
---|
153 | 0107 [U, S, V] = svd(TuneResponseMatrix, <span class="string">'econ'</span>); |
---|
154 | 0108 <span class="comment">% TuneResponseMatrix = U*S*V'</span> |
---|
155 | 0109 <span class="comment">%</span> |
---|
156 | 0110 <span class="comment">% The V matrix columns are the singular vectors in the quadrupole magnet space</span> |
---|
157 | 0111 <span class="comment">% The U matrix columns are the singular vectors in the TUNE space</span> |
---|
158 | 0112 <span class="comment">% U'*U=I and V*V'=I</span> |
---|
159 | 0113 <span class="comment">%</span> |
---|
160 | 0114 <span class="comment">% TUNECoef is the projection onto the columns of TuneResponseMatrix*V(:,Ivec) (same space as spanned by U)</span> |
---|
161 | 0115 <span class="comment">% Sometimes it's interesting to look at the size of these coefficients with singular value number.</span> |
---|
162 | 0116 TUNECoef = diag(diag(S).^(-1)) * U' * DeltaTune; |
---|
163 | 0117 <span class="comment">%</span> |
---|
164 | 0118 <span class="comment">% Convert the vector TUNECoef back to coefficents of TuneResponseMatrix</span> |
---|
165 | 0119 DelQuad = V * TUNECoef; |
---|
166 | 0120 |
---|
167 | 0121 |
---|
168 | 0122 <span class="comment">% 2. Square matrix solution</span> |
---|
169 | 0123 <span class="comment">% DelQuad = inv(TuneResponseMatrix) * DeltaTune;</span> |
---|
170 | 0124 |
---|
171 | 0125 |
---|
172 | 0126 <span class="comment">% 3. Least squares solution</span> |
---|
173 | 0127 <span class="comment">% DelQuad = inv(TuneResponseMatrix'*TuneResponseMatrix)*TuneResponseMatrix' * DeltaTune;</span> |
---|
174 | 0128 <span class="comment">%</span> |
---|
175 | 0129 <span class="comment">% see Matlab help for "Matrices and Linear Algebra" to see what this does</span> |
---|
176 | 0130 <span class="comment">% If overdetermined, then "\" is least squares</span> |
---|
177 | 0131 <span class="comment">%</span> |
---|
178 | 0132 <span class="comment">% If underdetermined (like more than 2 quadrupole families), then only the</span> |
---|
179 | 0133 <span class="comment">% columns with the 2 biggest norms will be keep. The rest of the quadupole</span> |
---|
180 | 0134 <span class="comment">% families with have zero effect. Hence, constraints would have to be added for</span> |
---|
181 | 0135 <span class="comment">% this method to work.</span> |
---|
182 | 0136 <span class="comment">% DelQuad = TuneResponseMatrix \ DeltaTune;</span> |
---|
183 | 0137 |
---|
184 | 0138 |
---|
185 | 0139 |
---|
186 | 0140 <span class="comment">% Make the setpoint change</span> |
---|
187 | 0141 SP = <a href="getsp.html" class="code" title="function [SP, tout, DataTime, ErrorFlag] = getsp(Family, varargin)">getsp</a>(ActuatorFamily, UnitsFlag{:}, ModeFlag{:}); |
---|
188 | 0142 |
---|
189 | 0143 <span class="keyword">if</span> iscell(SP) |
---|
190 | 0144 <span class="keyword">for</span> i = 1:length(SP) |
---|
191 | 0145 SP{i} = SP{i} + DelQuad(i); |
---|
192 | 0146 <span class="keyword">end</span> |
---|
193 | 0147 <span class="keyword">else</span> |
---|
194 | 0148 SP = SP + DelQuad; |
---|
195 | 0149 <span class="keyword">end</span> |
---|
196 | 0150 |
---|
197 | 0151 <a href="setsp.html" class="code" title="function ErrorFlag = setsp(Family, varargin)">setsp</a>(ActuatorFamily, SP, UnitsFlag{:}, ModeFlag{:}); |
---|
198 | 0152</pre></div> |
---|
199 | <hr><address>Generated on Mon 21-May-2007 15:29:18 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
200 | </body> |
---|
201 | </html> |
---|