| Description of mls_alloc |
mls_alloc
PURPOSE 
MLS_ALLOC - Control allocation using minimal least squares.
SYNOPSIS 
function [u,W,iter] = mls_alloc(B,v,umin,umax,Wv,Wu,ud,u,W,imax)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
- alloc_sim ALLOC_SIM - Control allocation simulation.
- qp_ca_sl Wrapper used in the QP control allocation Simulink block.
SOURCE CODE 
0001 function [u,W,iter] = mls_alloc(B,v,umin,umax,Wv,Wu,ud,u,W,imax)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 [k,m] = size(B);
0047
0048
0049 if nargin < 10
0050 imax = 100;
0051 if nargin < 9, u = (umin+umax)/2; W = zeros(m,1); end
0052 if nargin < 7, ud = zeros(m,1); end
0053 if nargin < 6, Wu = eye(m); end
0054 if nargin < 5, Wv = eye(k); end
0055 end
0056
0057
0058 phase = 1;
0059
0060
0061 A = Wv*B/Wu;
0062 b = Wv*(v-B*ud);
0063 xmin = Wu*(umin-ud);
0064 xmax = Wu*(umax-ud);
0065
0066 x = Wu*(u-ud);
0067 r = A*x-b;
0068
0069 i_free = W==0;
0070
0071 m_free = sum(i_free);
0072
0073
0074
0075 for iter = 1:imax
0076
0077
0078
0079
0080 if phase == 1
0081
0082
0083
0084
0085
0086 A_free = A(:,i_free);
0087
0088
0089
0090
0091
0092 if m_free <= k
0093
0094
0095
0096 p_free = -A_free\r;
0097 else
0098
0099
0100
0101
0102
0103
0104
0105
0106 [Q1,R1] = qr(A_free',0);
0107 p_free = -Q1*(R1'\r);
0108 end
0109
0110
0111 p = zeros(m,1);
0112 p(i_free) = p_free;
0113
0114 else
0115
0116
0117
0118
0119
0120 i_fixed = ~i_free;
0121
0122 m_fixed = m - m_free;
0123
0124
0125
0126 HT = U(i_fixed,:)';
0127
0128
0129
0130
0131 [V,Rtot] = qr(HT);
0132 V1 = V(:,1:m_fixed);
0133 V2 = V(:,m_fixed+1:end);
0134 R = Rtot(1:m_fixed,:);
0135
0136 s = -V2'*z;
0137 pz = V2*s;
0138 p = U*pz;
0139
0140 end
0141
0142
0143
0144
0145
0146 x_opt = x + p;
0147 infeasible = (x_opt < xmin) | (x_opt > xmax);
0148
0149 if ~any(infeasible(i_free))
0150
0151
0152
0153
0154
0155
0156 x = x_opt;
0157 if phase == 1
0158 r = r + A*p;
0159 else
0160 z = z + pz;
0161 end
0162
0163 if (phase == 1) & (m_free >= k)
0164
0165
0166 phase = 2;
0167
0168
0169 [Utot,Stot] = qr(A');
0170 U = Utot(:,k+1:end);
0171
0172 z = U'*x;
0173
0174 else
0175
0176
0177
0178 lambda = zeros(m,1);
0179
0180 if m_free < m
0181 if phase == 1
0182
0183 g = A'*r;
0184
0185 lambda = -W.*g;
0186
0187 else
0188
0189 lambda(i_fixed) = -W(i_fixed).*(R\(V1'*z));
0190 end
0191 end
0192
0193 if lambda >= -eps
0194
0195
0196
0197
0198
0199 u = Wu\x + ud;
0200 return;
0201 end
0202
0203
0204
0205
0206
0207
0208
0209 [lambda_neg,i_neg] = min(lambda);
0210 W(i_neg) = 0;
0211 i_free(i_neg) = 1;
0212 m_free = m_free + 1;
0213 end
0214 else
0215
0216
0217
0218
0219
0220
0221
0222 dist = ones(m,1);
0223 i_min = i_free & p<0;
0224 i_max = i_free & p>0;
0225
0226 dist(i_min) = (xmin(i_min) - x(i_min)) ./ p(i_min);
0227 dist(i_max) = (xmax(i_max) - x(i_max)) ./ p(i_max);
0228
0229
0230 [alpha,i_alpha] = min(dist);
0231
0232
0233 x = x + alpha*p;
0234 if phase == 1
0235 r = r + A*alpha*p;
0236 else
0237 z = z + alpha*pz;
0238 end
0239
0240
0241 W(i_alpha) = sign(p(i_alpha));
0242 i_free(i_alpha) = 0;
0243 m_free = m_free - 1;
0244
0245 end
0246
0247 end
0248
0249
0250 u = Wu\x + ud;
Generated on Wed 25-Aug-2004 14:38:35 by m2html © 2003
|
|