The transfer function 'sys' in your code corresponds to a 3rd-order system. However, the ODE system described in the anonymous function 'ode_pid()' represents a 2nd-order system. The formulation for the ODE of the system can be expressed as follows:
,
To convert it into state-space form, we have:
% Define the transfer function of the rotating beam system
sys = tf([1], [m, a, b, c])
sys =
1
-----------------------------------------
31600 s^3 + 1.757e06 s^2 + 83 s - 0.03855
Continuous-time transfer function.
% Checking the order of the system
systemOrder = order(sys)
systemOrder = 3
Therefore, I suggest modifying the 'ode_pid()' function as follows, incorporating the PID control function call:
% PID controller function
pidCtrl = @(t, Z) ...;
% ODEs of rotating beam system with PID controller function call
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.