How to fix the Index exceeds array dimensions ,Index value 2 exceeds valid range [1-1] for array 'Hv'
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
0 Comments
Answers (1)
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.
2 Comments
Walter Roberson
on 15 May 2021
Which of the matrices used to create Hv has at least 350 elements? You do not assign to Hv inside the loop, so to access Hv(i) with i=350 then Hv would have to have at least 350 elements in it, which would require that it be built from matrices with that many elements (exception: implicit expansion could create it with 39 elements divided as 25 and 14 in different directions)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!