下面这段代码是使用Matlab编写的PI控制器程序,定义了一个系统的传递函数,并定义了一个PI控制器,最后将系统和控制器组合在一起进行闭环控制,并绘制了闭环系统的单位步响应图像。适合初学者上手练习
clear all;
clc;
% Define the transfer function of the plant
num = [1];
den = [1, 6, 11, 6];
sys = tf(num,den);
% Define the PI controller
kp = 0.5;
ki = 1.5;
ctrl = kp + tf([ki, 0], 1);
% Close-loop transfer function
cl_tf = feedback(sys*ctrl, 1);
% Step response of the closed-loop system
step(cl_tf);
title('Step Response of the Closed-loop System with PI Control');
xlabel('Time (s)');
ylabel('Output');