hi
I have an system controled by PI control in simulink i can design it but in code when add PI control I can't do it
where my system is shown in next figure
any help

 Accepted Answer

Sam Chak
Sam Chak on 16 Aug 2022
Edited: Sam Chak on 16 Aug 2022
Here are the mathematical preliminaries for constructing the PI in ODE form.
[t, x] = ode45(@system, [0 10], [0; 0]);
plot(t, x(:,1), 'linewidth', 1.5)
grid on, xlabel('t'), ylabel('y(t)'), ylim([-0.2 1.2])
function dxdt = system(t, x)
dxdt = zeros(2, 1);
% construction of PI
r = 1; % reference signal
e = r - x(1); % error signal (based on Simulink)
Kp = 1/3; % proportional gain (user's Kp is 1)
Ki = - 1/3; % integral gain (user's Ki is 2)
u = Kp*e + Ki*x(2); % the PI thing (user's PI gains cause overshoot)
% the dynamics
A = 1;
B = 3;
dxdt(1) = A*x(1) + B*u; % the system
dxdt(2) = e; % for integral action
end

3 Comments

User's selection of PI gains cause 50% overshoot, which is normally undesirable in most situations.
The proposed PI gains in the Answer drive the system to have almost the same convergence time but without overshoot.
[t, x] = ode45(@system, [0 10], [0; 0]);
plot(t, x(:,1), 'linewidth', 1.5)
grid on, xlabel('t'), ylabel('y(t)')
function dxdt = system(t, x)
dxdt = zeros(2, 1);
% construction of PI
r = 1; % reference signal
e = r - x(1); % error signal (based on Simulink)
Kp = 1; % user's proportional gain
Ki = 2; % user's integral gain
u = Kp*e + Ki*x(2); % the PI thing
% the dynamics
A = 1;
B = 3;
dxdt(1) = A*x(1) + B*u; % the system
dxdt(2) = e; % for integral action
end
karim_karimo
karim_karimo on 17 Aug 2022
Edited: karim_karimo on 17 Aug 2022
thank you
can I use integral instead using the second state
The integral command requires the mathematical function.

Sign in to comment.

More Answers (0)

Asked:

on 15 Aug 2022

Commented:

on 18 Aug 2022

Community Treasure Hunt

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

Start Hunting!