Efficiently handle nonlinear models in Matlab (not Simulink)

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 :)

Réponses (1)

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 commentaires

thank you very much! I'm already using the ode-solvers, and I will definitely try your suggestion using symbolic math for the jacobians.
However, to interconnect nonlinear, or linear and nonlinear models, I still see no other way than explicitly writing the f-map on my own. I'd find it really nice if connect for linear dynamical models could do this and for example return a new f-map which can then be simulated using an ode-solver. Is there any functionality like this in matlab? Or do you have any idea how I could implement this on my own with reasonable effort?
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.
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.

Connectez-vous pour commenter.

Catégories

Produits

Version

R2022a

Commenté :

le 5 Juil 2022

Community Treasure Hunt

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

Start Hunting!

Translated by