If the error is defined as
then
P part is ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1099695/image.png)
I part is ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1099700/image.png)
D part is ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1099705/image.png)
and you can arrange then in the state-space form. For example, a Double Integrator system
can be rewritten in state-space as:
.The PID has 3 terms, and the state-space is in differential form. So you have no issue with the P and the D part, because they are part of the state variables. The I part is in integral form, so you have to create an additional state variable. See Example below:
[t, x] = ode45(@DIsystem, [0 20], [0; 0; 0]);
plot(t, x(:,1), 'linewidth', 1.5)
grid on, xlabel('t'), ylabel('y(t)'),
function dxdt = DIsystem(t, x)
u = - Kp*e - Ki*x(3) - Kd*x(2);
dxdt(1:2) = A*[x(1); x(2)] + B*u;