# How to improve the matlab code?

조회 수: 4(최근 30일)
CHEW Yen LI 2021년 5월 9일
편집: CHEW Yen LI 2021년 5월 10일
Hi ,recently i have develop the scalar reference governor in the simulink by using the matlab function block.Therefore, I have done my to develop the code, but there is a problem where the output of the system is not really track back the reference and have some undershoot. So I want ask some help how to improve this code or modified this code to make the output of the system become better. This is my output graph and the simulinik file is attached as follow
the red line is the output and the green line is the reference input.
hope to get some help, thx
.
function v = SRG_new(v_previous, r)
%state space eqaution of the closed loop system
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.05;
s=205; %s=max_y
k=1 ; % intialize k
S=100; %
%check the constrain,s is statisfied or not
for i=1:450
if S*(C*((I-A)^-1)*B+D)>(1-e)*s %first row of constriant not statisfied , k will decreases
k=k-0.00001;
else
if (S*C*A^i)+ S*(C*(I-A^i)*((I-A)^-1)*B+D)>s %second oand below row constriant not statisfied , k will decreases
k=k-0.00001;
else
k=k+0.00001; % if statisfied, k will increases
end
end
end
v=v_previous + k*(r-v_previous);
end

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by