| Description of wls_alloc |
wls_alloc
PURPOSE 
WLS_ALLOC - Control allocation using weighted least squares.
SYNOPSIS 
function [u,W,iter] = wls_alloc(B,v,umin,umax,Wv,Wu,ud,gam,u,W,imax)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
This function is called by:
- alloc_sim ALLOC_SIM - Control allocation simulation.
- dyn_ca_sl Wrapper used in the dynamic control allocation Simulink block.
- qp_ca_sl Wrapper used in the QP control allocation Simulink block.
SOURCE CODE 
0001 function [u,W,iter] = wls_alloc(B,v,umin,umax,Wv,Wu,ud,gam,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 m = length(umin);
0043
0044
0045 if nargin < 11
0046 imax = 100;
0047 [k,m] = size(B);
0048 if nargin < 10, u = (umin+umax)/2; W = zeros(m,1); end
0049 if nargin < 8, gam = 1e6; end
0050 if nargin < 7, ud = zeros(m,1); end
0051 if nargin < 6, Wu = eye(m); end
0052 if nargin < 5, Wv = eye(k); end
0053 end
0054
0055 gam_sq = sqrt(gam);
0056 A = [gam_sq*Wv*B ; Wu];
0057 b = [gam_sq*Wv*v ; Wu*ud];
0058
0059
0060 d = b - A*u;
0061
0062 i_free = W==0;
0063
0064
0065
0066 for iter = 1:imax
0067
0068
0069
0070
0071
0072 A_free = A(:,i_free);
0073
0074 p_free = A_free\d;
0075
0076 p = zeros(m,1);
0077
0078 p(i_free) = p_free;
0079
0080
0081
0082
0083
0084 u_opt = u + p;
0085 infeasible = (u_opt < umin) | (u_opt > umax);
0086
0087 if ~any(infeasible(i_free))
0088
0089
0090
0091
0092
0093
0094 u = u_opt;
0095 d = d - A_free*p_free;
0096
0097 lambda = W.*(A'*d);
0098
0099 if lambda >= -eps
0100
0101
0102
0103 return;
0104 end
0105
0106
0107
0108
0109
0110
0111
0112 [lambda_neg,i_neg] = min(lambda);
0113 W(i_neg) = 0;
0114 i_free(i_neg) = 1;
0115
0116 else
0117
0118
0119
0120
0121
0122
0123
0124 dist = ones(m,1);
0125 i_min = i_free & p<0;
0126 i_max = i_free & p>0;
0127
0128 dist(i_min) = (umin(i_min) - u(i_min)) ./ p(i_min);
0129 dist(i_max) = (umax(i_max) - u(i_max)) ./ p(i_max);
0130
0131
0132 [alpha,i_alpha] = min(dist);
0133
0134 u = u + alpha*p;
0135 d = d - A_free*alpha*p_free;
0136
0137
0138 W(i_alpha) = sign(p(i_alpha));
0139 i_free(i_alpha) = 0;
0140
0141 end
0142
0143 end
Generated on Wed 25-Aug-2004 14:38:35 by m2html © 2003
|
|