How to use ode45 to solve a system of two differential equation?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to use ode45 to solve this system:


(when q_1=q_1(t), q_2=q_2(t);
m, M, l, g, u - const)
There are no such examples in the documentation
How can I do it?
0 commentaires
Réponses (2)
Star Strider
le 22 Déc 2020
Code it correctly in the Symbollic Math Toolbox, then use odeFunction to turn it into a form that the ODE solvers can use.
Alternatively, you can do what I have gotten used to doing, and use odeToVectorField and matlabFunction to create the function to be used with the numerical ODE solvers.
0 commentaires
James Tursa
le 22 Déc 2020
Modifié(e) : James Tursa
le 22 Déc 2020
If you don't have the Symbolic Toolbox, here is the procedure:
1) Write your equations in matrix form:
F*qdotdot + G*qdot + H*q + stuff = otherstuff
where q = [q1;q2], qdot = [q1dot;d2dot], qdotdot = [q1dotdot;q2dotdot]
F is a 2x2 matrix, G is a 2x2 matrix, H is a 2x2 matrix, stuff is a 2x1 vector, otherstuff is a 2x1 vector
2) Solve for the highest order derivatives:
qdotdot = F \ (otherstuff - G*qdot - H*q - stuff)
You don't need the explicit solution for qdotdot here ... you can leave it in the form above if you want.
3) Define first order equations by redefining variables:
y = [q1;q2;q1dot;q2dot]
so y(1) = q1, y(2) = q2, y(3) = q1dot, y(4) = q2dot
4) Rewrite all of your derivatives according to these new definitions:
ydot = [y(3);y(4);qdotdot]
where the qdotdot is replaced with the code in step (2) but using y(1), y(2), y(3), y(4) in place of q1, q2, q1dot, q2dot.
5) Code up step (4)
Use this as your function (handle) to feed to ode45( ).
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!