How to optimize new test problem using PlatEMO? - matlab

I tried to follow the main tutorial of PlatEMO but I failed to compile it. I tried to modify an already existed function but I've got too many errors.
This is the code I already tried:
classdef counster < PROBLEM
%HELP COUNSTER
methods
%% Initialization
function obj = counster()
obj.Global.M = 2;
if isempty(obj.Global.D)
obj.Global.D = 2;
end
obj.Global.lower =[0,zeros(1,obj.Global.D-1)-2];
obj.Global.upper = [1,zeros(1,obj.Global.D-1)+2];
obj.Global.encoding = 'real';
end
%% Calculate objective values
function PopObj = CalObj(obj,X)
PopObj(:,1) = X(1);
PopObj(:,2) = (1 + X(2))/X(1);
end
%% Calculate constraint violations
function PopCon = CalCon(obj,X)
PopCon(:,1)=-9*X(1)-X(2)+6;
PopCon(:,2)= -9*X(1)-X(2)+1;
end
end
end
and this is an example of built-in function which is correctly working:
classdef CF4 < PROBLEM
% <problem> <CF>
% Constrained benchmark MOP
%------------------------------- Reference --------------------------------
% Q. Zhang, A. Zhou, S. Zhao, P. N. Suganthan, W. Liu, and S. Tiwari,
% Multiobjective optimization test instances for the CEC 2009 special
% session and competition, School of CS & EE, University of Essex, Working
% Report CES-487, 2009.
%------------------------------- Copyright --------------------------------
% Copyright (c) 2018-2019 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------
methods
%% Initialization
function obj = CF4()
obj.Global.M = 2;
if isempty(obj.Global.D)
obj.Global.D = 10;
end
obj.Global.lower = [0,zeros(1,obj.Global.D-1)-2];
obj.Global.upper = [1,zeros(1,obj.Global.D-1)+2];
obj.Global.encoding = 'real';
end
%% Calculate objective values
function PopObj = CalObj(obj,X)
D = size(X,2);
J1 = 3 : 2 : D;
J2 = 2 : 2 : D;
Y = X - sin(6*pi*repmat(X(:,1),1,D)+repmat(1:D,size(X,1),1)*pi/D);
h = Y.^2;
temp = Y(:,2) < 3/2*(1-sqrt(1/2));
h(temp,2) = abs(Y(temp,2));
h(~temp,2) = 0.125 + (Y(~temp,2)-1).^2;
PopObj(:,1) = X(:,1) + sum(h(:,J1),2);
PopObj(:,2) = 1-X(:,1) + sum(h(:,J2),2);
end
%% Calculate constraint violations
function PopCon = CalCon(obj,X)
t = X(:,2) - sin(6*pi*X(:,1)+2*pi/size(X,2)) - 0.5*X(:,1) + 0.25;
PopCon = -t./(1+exp(4*abs(t)));
end
%% Sample reference points on Pareto front
function P = PF(obj,N)
P(:,1) = (0:1/(N-1):1)';
P(:,2) = 1 - P(:,1);
temp1 = 0.5<P(:,1) & P(:,1)<=0.75;
temp2 = 0.75<P(:,1);
P(temp1,2) = -0.5*P(temp1,1)+3/4;
P(temp2,2) = 1 - P(temp2,1)+0.125;
end
end
end
>> main('-algorithm',#MOPSO,'-problem',#counster,'-N',200,'-M',10);
It meant to plot a pareto front of counster problem but I have got this:
Index exceeds matrix dimensions.
Error in INDIVIDUAL (line 79)
obj(i).obj = Objs(i,:);
Error in GLOBAL/Initialization (line 151)
Population = INDIVIDUAL(obj.problem.Init(N));
Error in MOPSO (line 23)
Population = Global.Initialization();
Error in GLOBAL/Start (line 120)
obj.algorithm(obj);
Error in main (line 62)
Global.Start();

Related

Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN

The following code uses rk4 to simulate the dynamics defined via fe function. However, I encountered the warning Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. .
I felt that the function defined in fe, sometimes the Numerator equals zero, thus creates singularity. But I don't know how to avoid it.
Should I change the function formula (I prefer not to), or should I revise the code, or change the solver?
Thank you in advance for any suggestion.
clear;
global G
tic
n=40;
A = ones(n) - eye(n);
G = graph(A);
num_samples =1;
p.G = A
dim_G = size(p.G);
p.K = 1;
p.N = dim_G(1);
nIters = 2000;
tBegin = 0;
tEnd = 100;
% initial condition
Init = -pi + 2*pi.*rand(p.N,num_samples);
dim_thetaInit = size(Init);
Init = Init(:,1);
[t,sol] = rk4(#fe,tBegin,tEnd,Init,nIters,p);
function td = fe(t,theta,p)
[theta_i,theta_j] = meshgrid(theta);
adj_matrix = p.G;
a = 4;
b = 1;
td= sum(adj_matrix'.*( ( b*cos(theta_i-theta_j) * (2*a^2*cos(theta_i-theta_j)*sin(theta_i-theta_j)-2*b^2*cos(theta_i-theta_j)*sin(theta_i-theta_j)) ) / ( 2*(b^2*(cos(theta_i-theta_j))^2+a^2*(sin(theta_i-theta_j))^2)^(3/2) ) + (b*sin(theta_i-theta_j))/( sqrt( b^2*cos(theta_i-theta_j)^2 + a^2*sin(theta_i-theta_j)^2 ) ) ),1)';
end
function [T,Y] = rk4(f,a,b,ya,m,p)
%---------------------------------------------------------------------------
% RK4 Runge-Kutta solution for y' = f(t,y) with y(a) = ya .
% Sample call
% [T,Y] = rk4('f',a,b,ya,m)
% Inputs
% f name of the function
% a left endpoint of [a,b]
% b right endpoint of [a,b]
% ya initial value
% m number of steps
% p Kuramoto function arguments
% Return
% T solution: vector of abscissas
% Y solution: vector of ordinates
%
% NUMERICAL METHODS: MATLAB Programs, (c) John H . Mathews 1995
% To accompany the text:
% NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
% Prentice Hall, Englewood Cliffs, New Jersey, 07632, U . S . A .
% Prentice Hall, Inc .; USA, Canada, Mexico ISBN 0-13-624990-6
% Prentice Hall, International Editions: ISBN 0-13-625047-5
% This free software is compliments of the author .
% E-mail address: in % "mathews#fullerton.edu"
%
% Algorithm 9.4 (Runge-Kutta Method of Order 4) .
% Section 9.5, Runge-Kutta Methods, Page 460
%---------------------------------------------------------------------------
h = (b - a)/m;
T = zeros(1,m+1);
size(ya,1)
Y = zeros(size(ya,1),m+1);
T(1) = a;
Y(:,1) = ya;
for j=1:m
tj = T(j);
yj = Y(:,j);
k1 = h*feval(f,tj,yj,p);
k2 = h*feval(f,tj+h/2,yj+k1/2,p);
k3 = h*feval(f,tj+h/2,yj+k2/2,p);
k4 = h*feval(f,tj+h,yj+k3,p);
Y(:,j+1) = yj + (k1 + 2*k2 + 2*k3 + k4)/6;
T(j+1) = a + h*j;
end
end

Fast approach in matlab to estimate linear regression with AR terms

I am trying to estimate regression and AR parameters for (loads of) linear regressions with AR error terms. (You could also think of this as a MA process with exogenous variables):
, where
, with lags of length p
I am following the official matlab recommendations and use regArima to set up a number of regressions and extract regression and AR parameters (see reproducible example below).
The problem: regArima is slow! For 5 regressions, matlab needs 14.24sec. And I intend to run a large number of different regression models. Is there any quicker method around?
y = rand(100,1);
r2 = rand(100,1);
r3 = rand(100,1);
r4 = rand(100,1);
r5 = rand(100,1);
exo = [r2 r3 r4 r5];
tic
for p = 0:4
Mdl = regARIMA(3,0,0);
[EstMdl, ~, LogL] = estimate(Mdl,y,'X',exo,'Display','off');
end
toc
Unlike the regArima function which uses Maximum Likelihood, the Cochrane-Orcutt prodecure relies on an iteration of OLS regression. There are a few more particularities when this approach is valid (refer to the link posted). But for the aim of this question, the appraoch is valid, and fast!
I modified James Le Sage's code which covers only AR lags of order 1, to cover lags of order p.
function result = olsc(y,x,arterms)
% PURPOSE: computes Cochrane-Orcutt ols Regression for AR1 errors
%---------------------------------------------------
% USAGE: results = olsc(y,x)
% where: y = dependent variable vector (nobs x 1)
% x = independent variables matrix (nobs x nvar)
%---------------------------------------------------
% RETURNS: a structure
% results.meth = 'olsc'
% results.beta = bhat estimates
% results.rho = rho estimate
% results.tstat = t-stats
% results.trho = t-statistic for rho estimate
% results.yhat = yhat
% results.resid = residuals
% results.sige = e'*e/(n-k)
% results.rsqr = rsquared
% results.rbar = rbar-squared
% results.iter = niter x 3 matrix of [rho converg iteration#]
% results.nobs = nobs
% results.nvar = nvars
% results.y = y data vector
% --------------------------------------------------
% SEE ALSO: prt_reg(results), plt_reg(results)
%---------------------------------------------------
% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl#jpl.econ.utoledo.edu
% do error checking on inputs
if (nargin ~= 3); error('Wrong # of arguments to olsc'); end;
[nobs nvar] = size(x);
[nobs2 junk] = size(y);
if (nobs ~= nobs2); error('x and y must have same # obs in olsc'); end;
% ----- setup parameters
ITERMAX = 100;
converg = 1.0;
rho = zeros(arterms,1);
iter = 1;
% xtmp = lag(x,1);
% ytmp = lag(y,1);
% truncate 1st observation to feed the lag
% xlag = x(1:nobs-1,:);
% ylag = y(1:nobs-1,1);
yt = y(1+arterms:nobs,1);
xt = x(1+arterms:nobs,:);
xlag = zeros(nobs-arterms,arterms);
for tt = 1 : arterms
xlag(:,nvar*(tt-1)+1:nvar*(tt-1)+nvar) = x(arterms-tt+1:nobs-tt,:);
end
ylag = zeros(nobs-arterms,arterms);
for tt = 1 : arterms
ylag(:,tt) = y(arterms-tt+1:nobs-tt,:);
end
% setup storage for iteration results
iterout = zeros(ITERMAX,3);
while (converg > 0.0001) & (iter < ITERMAX),
% step 1, using intial rho = 0, do OLS to get bhat
ystar = yt - ylag*rho;
xstar = zeros(nobs-arterms,nvar);
for ii = 1 : nvar
tmp = zeros(1,arterms);
for tt = 1:arterms
tmp(1,tt)=ii+nvar*(tt-1);
end
xstar(:,ii) = xt(:,ii) - xlag(:,tmp)*rho;
end
beta = (xstar'*xstar)\xstar' * ystar;
e = y - x*beta;
% truncate 1st observation to account for the lag
et = e(1+arterms:nobs,1);
elagt = zeros(nobs-arterms,arterms);
for tt = 1 : arterms
elagt(:,tt) = e(arterms-tt+1:nobs-tt,:);
end
% step 2, update estimate of rho using residuals
% from step 1
res_rho = (elagt'*elagt)\elagt' * et;
rho_last = rho;
rho = res_rho;
converg = sum(abs(rho - rho_last));
% iterout(iter,1) = rho;
iterout(iter,2) = converg;
iterout(iter,3) = iter;
iter = iter + 1;
end; % end of while loop
if iter == ITERMAX
% error('ols_corc did not converge in 100 iterations');
print('ols_corc did not converge in 100 iterations');
end;
result.iter= iterout(1:iter-1,:);
% after convergence produce a final set of estimates using rho-value
ystar = yt - ylag*rho;
xstar = zeros(nobs-arterms,nvar);
for ii = 1 : nvar
tmp = zeros(1,arterms);
for tt = 1:arterms
tmp(1,tt)=ii+nvar*(tt-1);
end
xstar(:,ii) = xt(:,ii) - xlag(:,tmp)*rho;
end
result.beta = (xstar'*xstar)\xstar' * ystar;
e = y - x*result.beta;
et = e(1+arterms:nobs,1);
elagt = zeros(nobs-arterms,arterms);
for tt = 1 : arterms
elagt(:,tt) = e(arterms-tt+1:nobs-tt,:);
end
u = et - elagt*rho;
result.vare = std(u)^2;
result.meth = 'olsc';
result.rho = rho;
result.iter = iterout(1:iter-1,:);
% % compute t-statistic for rho
% varrho = (1-rho*rho)/(nobs-2);
% result.trho = rho/sqrt(varrho);
(I did not adapt in the last 2 lines the t-test for rho vectors of length p, but this should be straight forward to do..)

MATLAB, ols function not working from an Econometrics toolbox [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am trying to run a simple OLS regression,
%Demonstrate regression using the ols() function
%Step 1. Load the data
clear;
clc;
y=[1 2 3 4 5]
x=[1 2 3 4 5]
result=ols(y,x);
prt(result);
prt(result);
I am using James LeSages econometric tool box and the OLS function is here,
function results=ols(y,x)
% PURPOSE: least-squares regression
%---------------------------------------------------
% USAGE: results = ols(y,x)
% where: y = dependent variable vector (nobs x 1)
% x = independent variables matrix (nobs x nvar)
%---------------------------------------------------
% RETURNS: a structure
% results.meth = 'ols'
% results.beta = bhat (nvar x 1)
% results.tstat = t-stats (nvar x 1)
% results.bstd = std deviations for bhat (nvar x 1)
% results.yhat = yhat (nobs x 1)
% results.resid = residuals (nobs x 1)
% results.sige = e'*e/(n-k) scalar
% results.rsqr = rsquared scalar
% results.rbar = rbar-squared scalar
% results.dw = Durbin-Watson Statistic
% results.nobs = nobs
% results.nvar = nvars
% results.y = y data vector (nobs x 1)
% results.bint = (nvar x2 ) vector with 95% confidence intervals on beta
%---------------------------------------------------
% SEE ALSO: prt(results), plt(results)
%---------------------------------------------------
% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jlesage#spatial-econometrics.com
%
% Barry Dillon (CICG Equity)
% added the 95% confidence intervals on bhat
if (nargin ~= 2); error('Wrong # of arguments to ols');
else
[nobs nvar] = size(x); [nobs2 junk] = size(y);
if (nobs ~= nobs2); error('x and y must have same # obs in ols');
end;
end;
results.meth = 'ols';
results.y = y;
results.nobs = nobs;
results.nvar = nvar;
if nobs < 10000
[q r] = qr(x,0);
xpxi = (r'*r)\eye(nvar);
else % use Cholesky for very large problems
xpxi = (x'*x)\eye(nvar);
end;
results.beta = xpxi*(x'*y);
results.yhat = x*results.beta;
results.resid = y - results.yhat;
sigu = results.resid'*results.resid;
results.sige = sigu/(nobs-nvar);
tmp = (results.sige)*(diag(xpxi));
sigb=sqrt(tmp);
results.bstd = sigb;
tcrit=-tdis_inv(.025,nobs);
results.bint=[results.beta-tcrit.*sigb, results.beta+tcrit.*sigb];
results.tstat = results.beta./(sqrt(tmp));
ym = y - mean(y);
rsqr1 = sigu;
rsqr2 = ym'*ym;
results.rsqr = 1.0 - rsqr1/rsqr2; % r-squared
rsqr1 = rsqr1/(nobs-nvar);
rsqr2 = rsqr2/(nobs-1.0);
if rsqr2 ~= 0
results.rbar = 1 - (rsqr1/rsqr2); % rbar-squared
else
results.rbar = results.rsqr;
end;
ediff = results.resid(2:nobs) - results.resid(1:nobs-1);
results.dw = (ediff'*ediff)/sigu; % durbin-watson
I get an error when I try to run this.
I get an error in line 64.
Is this an obvious fix? The function would be really useful and hopefully, someone can help.
https://www.spatial-econometrics.com/
Here is the econometrics tool box.
So my top code is calling for the ols function.
I think this is due to not having all the relevant functions in the same MATLAB folder, does this make a difference?
Your missing a few dependencies. Your ols file looks like the one in this matlab-central contribution: https://ch.mathworks.com/matlabcentral/fileexchange/45093-time-frequency-generalized-phase-synchrony-for-eeg-signal-analysis
It even states in it's description the same source than the one you provided. And it contains all required dependencies. Maybe too much for your usecase...

minimum-redundancy maximum-relevancy (MRMR) for feature selection

I am using a filter measure in feature selection called (MRMR) minimum-redundancy maximum-relevancy. After i run the code below
function testselection
addpath('C:\Users\Desktop\mRMR_0.9_compiled\mi_0.9');
FeaturesFile = dlmread('test.txt')
[x,y]=size(FeaturesFile)
Features=FeaturesFile(:,1:y-1)
classLeble=FeaturesFile(:,y)
[fea] = mrmr_mid_d(Features, classLeble, 5)
end
I got the following error
Undefined function or variable 'estpab'.
Error in mutualinfo (line 21)
[p12, p1, p2] = estpab(vec1,vec2);
Error in mrmr_mid_d (line 17)
t(i) = mutualinfo(d(:,i), f);
Error in mrmr (line 9)
[fea] = mrmr_mid_d(Features, classLeble, 5);
The code for mrmr_mid_d as below
function [fea] = mrmr_mid_d(d, f, K)
% function [fea] = mrmr_mid_d(d, f, K)
%
% MID scheme according to MRMR
%
% By Hanchuan Peng
% April 16, 2003
%
bdisp=0;
nd = size(d,2);
nc = size(d,1);
t1=cputime;
for i=1:nd,
t(i) = mutualinfo(d(:,i), f);
end;
fprintf('calculate the marginal dmi costs %5.1fs.\n', cputime-t1);
[tmp, idxs] = sort(-t);
fea_base = idxs(1:K);
fea(1) = idxs(1);
KMAX = min(1000,nd); %500
idxleft = idxs(2:KMAX);
k=1;
if bdisp==1,
fprintf('k=1 cost_time=(N/A) cur_fea=%d #left_cand=%d\n', ...
fea(k), length(idxleft));
end;
for k=2:K,
t1=cputime;
ncand = length(idxleft);
curlastfea = length(fea);
for i=1:ncand,
t_mi(i) = mutualinfo(d(:,idxleft(i)), f);
mi_array(idxleft(i),curlastfea) = getmultimi(d(:,fea(curlastfea)), d(:,idxleft(i)));
c_mi(i) = mean(mi_array(idxleft(i), :));
end;
[tmp, fea(k)] = max(t_mi(1:ncand) - c_mi(1:ncand));
tmpidx = fea(k); fea(k) = idxleft(tmpidx); idxleft(tmpidx) = [];
if bdisp==1,
fprintf('k=%d cost_time=%5.4f cur_fea=%d #left_cand=%d\n', ...
k, cputime-t1, fea(k), length(idxleft));
end;
end;
return;
%=====================================
function c = getmultimi(da, dt)
for i=1:size(da,2),
c(i) = mutualinfo(da(:,i), dt);
end;
And the code for mutualinfo as follows
function h = mutualinfo(vec1,vec2)
%=========================================================
%
%This is a prog in the MutualInfo 0.9 package written by
% Hanchuan Peng.
%
%Disclaimer: The author of program is Hanchuan Peng
% at <penghanchuan#yahoo.com> and <phc#cbmv.jhu.edu>.
%
%The CopyRight is reserved by the author.
%
%Last modification: April/19/2002
%
%========================================================
%
% h = mutualinfo(vec1,vec2)
% calculate the mutual information of two vectors
% By Hanchuan Peng, April/2002
%
[p12, p1, p2] = estpab(vec1,vec2);
h = estmutualinfo(p12,p1,p2);
Could someone know what is the problem?
If you use this Mutual information computation package, you can see, the estpab function compiled only for some platforms (there are estpab.dll for Win32 platform, estpab.mexglx the ELF32 file and estpab.mexmac for Mac).
So, you have to recompile this package for your platform.
First of all you have to configure mex building system. Call mex -setup and select appropriate compiler.
Than you can recompile the Mutual information computation package by calling makeosmex.
Note: If you get some errors during compilation like
d:\MATLAB work\mi\estcondentropy.cpp(65) : error C2668: 'log' : ambiguous call to overloaded function
you have to modify appropriate line (65 in this example) in appropriate file (estcondentropy.cpp in this example) from the muInf /= log(2); to muInf /= log(2.0);
In the path C:\Users\Desktop\ isn't the user missing?
Usually windows paths are something like C:\Users\Username\Desktop\
You are probably adding the wrong path, so the program cannot find the function estpab at all.

error function aborted matlab

Hi i am running a model in simulink from matlab and i am taking this error
Error using run (line 28) Call to MATLAB function aborted: The first
input argument of the "mpc" command must be one of the following: an
LTI object, an IDMODEL object or a structure of models and offsets.
Block Subsystem2/Control plant (#38) While executing: State During
Action
The embedeed block that i take the erro contains the code
function w0u = MPC(p,x,Sb_bus,Sb,vt,q,theta0,ku,xs,u,vf,KvP,KvI,Kp,Ki,Kd,Droop,DroopAvr,v0,wb,r,t0,umaxnow,time,samplingsTime,Rn,Qn,Rw,Qw,ud,uMinMPC,uMaxMPC,udMaxMPC,wmin,wminw,wmax,wmaxw,tFLR,aFLR,genset3connected,debuggingfile,mpcOn,mpcValSaveTime,mpcValFileName,useUMaxNow,wNLstart)
coder.extrinsic('mpc');
w0u = zeros(2,1);
[w0u] = mpc(p,x,Sb_bus,Sb,vt,q,theta0,ku,xs,u,vf,KvP,KvI,Kp,Ki,Kd,Droop,DroopAvr,v0,wb,r,t0,umaxnow,time,samplingsTime,Rn,Qn,Rw,Qw,ud,uMinMPC,uMaxMPC,udMaxMPC,wmin,wminw,wmax,wmaxw,tFLR,aFLR,genset3connected,debuggingfile,mpcOn,mpcValSaveTime,mpcValFileName,useUMaxNow,wNLstart);
end
And the function mpc is
function [w0u] = mpc(p,Sb_bus,Sb,vt,q,x,theta0,ku,xs,u,umaxnow,vf,KvP,KvI,Kp,Ki,Kd,Droop,DroopAvr,v0,wb,r,t0,time,samplingsTime,Rn,Qn,Rw,Qw,ud,uMinMPC,uMaxMPC,udMaxMPC,wmin,wminw,wmax,wmaxw,tFLR,aFLR,genset3connected,debuggingfile,mpcOn,mpcValSaveTime,mpcValFileName,useUMaxNow,wNLstart)
persistent tupdated w0set
eml.extrinsic('saveVariables');
H = [10; 7];
D = [.02;.025];
if (isempty(tupdated))
% Initialize variables
tupdated = time;
w0set = wNLstart;
elseif (time < t0)
% Wait until t0
elseif (mpcOn == 0)
% If turned off, do nothing.
elseif (time >= tupdated + samplingsTime)
% Update w0
Pbus = sum(p.*Sb)/sum(Sb);
Qbus = sum(q.*Sb)/sum(Sb);
pFLR = aFLR*Sb(end)/Sb_bus*Pbus;
X = [Pbus;Qbus;x];
u0 = u;
udw = ud(1);
%% Calculate the state space equations
[A B B0 Cu Du ~, ud] = makeLinearSystem(H,D,p,Sb_bus,Sb,q,X,vf,vt,theta0,ku,xs,u0,wb,r,KvP,KvI,Kp,Ki,Kd,Droop,DroopAvr,w0set,v0,samplingsTime,ud);
[Aw Bw B0w Cuw Duw ~, udw] = makeLinearWorstCaseSystem(H,D,p,Sb_bus,Sb,q,X,vf,vt,theta0,ku,xs,u0,wb,r,KvP,KvI,Kp,Ki,Kd,Droop,DroopAvr,w0set,v0,samplingsTime,genset3connected,pFLR,udw);
%% Discretize
if(genset3connected)
% Discretize system for normal case
[Ad Bd B0d] = makediscrete(A,B,B0,samplingsTime);
% Discretize system after FLR reacts
[AdFLRp, ~, ~] = makediscrete(Aw,Bw,B0w,samplingsTime-tFLR);
else
% Sets Ad, Bd, B0d and AdFLRp to remove compilation error (matrices
% must have the same size for all cases)
Ad = A;
Bd = B;
B0d = B0;
AdFLRp = Aw;
end
% Discretize system for failure case
[Adw Bdw B0dw] = makediscrete(Aw,Bw,B0w,samplingsTime);
%% Find input optimal
[dw0opt PHI PSI dw] = findInput(X,Ad,Bd,B0d,Cu,Du,Adw,Bdw,B0dw,Cuw,Duw,AdFLRp,pFLR,Rn,Qn,Rw,Qw,ud,udw,u,umaxnow,uMinMPC,uMaxMPC,udMaxMPC,wmin,wmax,wminw,wmaxw,p,Sb,genset3connected,time,debuggingfile,useUMaxNow);
%% Save internal values for plotting
if(mpcValSaveTime >= time && mpcValSaveTime< time + samplingsTime)
saveVariables(mpcValFileName,PHI,PSI,dw)
end
w0set = w0set + dw0opt;
tupdated = time;
end
w0u =w0set;
end
what i have to do?