How to integrate a control system by ode45 with PID control input ?
Show older comments
I want to simulate a control system using ode45 function. The system model can be expressed as
, where the control input u is the PID control which can be expressed as
. The
is the desired state. My question is how to integrate the error in the ode model as illustrated in the following code example, since we only obtain the current time state X when the f function is called
function dX = f(t,X,P)
% ...
% ...
u = P.Kp * (P.Xd - X) + P.Ki * (P.Xd - X) + ... ; % How to integrate the error Xd - X ?
end
Accepted Answer
More Answers (1)
Torsten
on 20 Nov 2025
Add a second differential equation
dV/dt = P.Xd - X
with initial condition
V(0) = 0
Then
V(t) = integral_{0}^{t} (P.Xd - X) dt
Categories
Find more on Ordinary Differential Equations 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!