How to transform a second order ODE to the format xddot=A.X+B.U
Mostra commenti meno recenti
I have a system of ODEs of the type
that are currently simbolic functions and I want to find a way to obtain it's matrices automatically cause the system is too big to do it by hand.
1 Commento
Ítalo Almeida
il 8 Feb 2023
Modificato: Ítalo Almeida
il 8 Feb 2023
Risposte (3)
Star Strider
il 30 Gen 2023
0 voti
Those should work if you want to solve them using the MATLAB ordinary differential equation integrators.
If you want to use them with the Control System Toolbox, that will require a different approach.
2 Commenti
Ítalo Almeida
il 6 Feb 2023
Star Strider
il 6 Feb 2023
Modificato: Star Strider
il 7 Feb 2023
The linear control systems assume that all the derivatives are first-degree. The odeToVectorField function will put them in that form, and the second ‘Subs’ output will give the row order of the variables.
Adding:
sympref('AbbreviateOutput',false);
after the initial syms call might also be helpful.
EDIT — (7 Feb 2023 at 11:54)
Another option (that I do not often use and so forgot about) is the odeFunction function. That might be more appropriate here.
.
Hi Ítalo,
Let p = x and q = xdot. Then the standard, first order state space model is
[pdot;qdot] = [zeros(n) eye(n); A zeros(n)] * [p ; q] + [0*B; B] * u;
For example, let A = 2 and B = 3. The output of the system is x.
A = 2; B = 3;
hss = ss([0 1;A 0],[0*B;B],[1 0],0)
htf = tf(hss)
We see from the transfer function that the input/ouput ode is: ydddot = 2*y + 3*u, exactly as it should be because y = x.
The odeToVectorField() should work. But since you already have the linear 2nd-order system in this ODE form
, then you should be able to readily transform it to the State-space form
through some basic matrix operations:
, where Then, the optimal gain
can be obtained from the lqr() function.
Check this example if this is something you are look for. You can also try applying the sparse 2nd-order state-space model as recommended by @Paul.
A = magic(4)
B = diag([2, 3, 5, 7])
n = size(A)
Aa = [zeros(n) eye(n);
A zeros(n)]
Bb = [zeros(n); B]
K = lqr(Aa, Bb, eye(2*n), eye(n))
2 Commenti
Ítalo Almeida
il 8 Feb 2023
Sam Chak
il 8 Feb 2023
Sounds like a finite horizon problem. You can check if you can apply one of the QP solvers for solving the Riccati Differential Equations. You can find some info here:
Categorie
Scopri di più su Matrix Computations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!