4 views (last 30 days)

Show older comments

Hi, I;m having some error when run a code as shown in below, the code is the code for scalar reference governor. after I run the code and it show me the 'Index exceeds array dimensions. Index value 2 exceeds valid range [1-1] for array 'Hv'. Error in 'SRG_LP/SRG' (line 18)' Hope those are experts in this fiels can help me solve this error. For Hx and Hv is the maximal admissible output sets(MAS) with the matrices A,B,C,D where MAS=Hx+Hv<=s where s is the maximal output that need to be statisfied

A=[-21.22 1;-275.5 0];

B=[11.02;275.5];

C=[1 0];

D=0;

I=eye(2);

Hx=(C*A);

Hv= C*(I-A)*((I-A)^-1)*B;

e=0.2;

s=100; %s=max_y

k=1 ; % intialize k

%check the constrain,s is statisfied or not

for i=1:350

if Hx(i)+Hv(i)<=(1-e)*s %first row of constriant not statisfied , k will decreases

k=k+0.00000001;

elseif Hx(i)+Hv(i)<=s %second oand below row constriant not statisfied , k will decreases

k=k+0.00002;

else

k=k-0.000000008;

end

end

v=v_previous + k*(r-v_previous);

end

Image Analyst
on 15 May 2021

I don't know what these formulas are doing

Hx=(C*A);

Hv= C*(I-A)*((I-A)^-1)*B;

but Hx is a 1x2 row vector while Hv is a scalar. To reference Hv(i) where i is bigger than 1, you're going to need it to be a vector with 350 elements. Same for Hx for i greater than 2.

Walter Roberson
on 15 May 2021

VBBV
on 16 May 2021

%if true

h = ones(350,1);

for i=1:350

if Hx*h(i)+Hv*h(i)<=(1-e)*s %first row of constriant not statisfied , k will decreases

k=k+0.00000001;

elseif Hx*h(i)+Hv*h(i)<=s %second oand below row constriant not statisfied , k will decreases

k=k+0.00002;

else

k=k-0.000000008;

end

end

You can do constraint check this way

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!