Efficiently handle nonlinear models in Matlab (not Simulink)

4 次查看(过去 30 天)
Hello,
I wanted to ask if there is a framework for non-linear models in Matlab, similar to that for linear dynamical systems (ss, lsim, connect, etc.). I need to create some examples for a control theory lecture and would like to compare linear and non-linear systems. For example, I've got a nonlinear model of a simple inverted pendulum, and functions for the jacobians of the dynamics and the output map. Now I implement some controllers (state feedback, LQR, ...) at a stationary point and compare the linear and non-linear closed-loop. I know how to do it for one single model, but i'd like to easily switch the models and stationary points. I already made some simple data structures and functions for automated plotting, controller synthesis and interconnections. However, this took me quite some time and it's not easily adapted to other models with possibly different dimensions. So I wondered if there was an already implemented framework similar to what exists for linear systems with functions like lsim for calculating responses or connect for creating interconnections, where you can give names to inputs and outputs etc.
I'm happy about any hints on how to work with nonlinear models more efficiently :)

回答(1 个)

Sam Chak
Sam Chak 2022-6-28
For non-stiff nonlinear models, the ode45() is the general way of simulating them, and the nonlinear model is typically written in a function file:
function dydt = nonlinmod(t, y)
% Inverted Pendulum
dydt = zeros(2, 1);
g = 9.8; % gravity (m/s^2)
L = 0.49; % length of pendulum (m)
dydt(1) = y(2);
dydt(2) = (g/L)*sin(y(1));
% % Duffing oscillator
% dydt = zeros(2, 1);
% c = 1;
% k = 1;
% a = 1;
% gamma = 1;
% omega = 1;
% dydt(1) = y(2);
% dydt(2) = - c*y(2) - k*(1 + a^2*y(1)^2)*y(1) + gamma*cos(omega*t);
end
To find the Jacobian matrix of multiple nonlinear models, you can probably do this:
syms F(x, y) g L c k a
F(x, y) = [y; (g/L)*sin(x)]; % inverted pendulum
H(x, y) = [y; - c*y - k*(1 + a^2*x^2)*x]; % unforced Duffing oscillator
gradF = jacobian(F(x, y), [x; y])
gradF = 
gradH = jacobian(H(x, y), [x; y])
gradH = 
  3 个评论
Sam Chak
Sam Chak 2022-7-5
Maybe in future, they will release some advanced features for nonlinear systems.
At the moemnt, I normally use odeToVectorField() to convert multiple nonlinear differential equations to a system of first-order differential equations.
Please check if it helps in your case.
Paul
Paul 2022-7-5
You might be able to write interconnection functions, like series, parallel, and feedback using the Symbolic Math Toolbox. Whether or not it could be done effectively with "reasonable" effort is unknown until you try and will probably depend on how feature-rich you want the code to be.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Linearization 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by