Effacer les filtres
Effacer les filtres

Calling external time dependent variables inside ODE45 function

11 vues (au cours des 30 derniers jours)
Hassan Alkomy
Hassan Alkomy le 10 Mai 2020
Commenté : Hassan Alkomy le 10 Mai 2020
I want to use ODE45 to solve a system of ODEs. The ODEs depend on time dependent variables that I have from another script. These time dependent variables are saved in the work space as variable. I want to load them (or use them somehow) inside the ODE45 function.
To make it clear, the variables that I want to use are names as (POS, VEL, ACC) and all of them are peicewise matrices (like peicewise functions but each has 3 rows).
One of them as an example:
piecewise(t in Dom::Interval([1], [2]), matrix([[3.0416666666666666666666666666667*t^5 - 20.208333333333333333333333333333*t^4 + 49.166666666666666666666666666667*t^3 - 53.333333333333333333333333333333*t^2 + 26.666666666666666666666666666667*t - 5.3333333333333333333333333333333], [0], [- 1.1458333333333333333333333333333*t^5 + 8.2291666666666666666666666666667*t^4 - 22.083333333333333333333333333333*t^3 + 26.666666666666666666666666666667*t^2 - 13.333333333333333333333333333333*t + 2.6666666666666666666666666666667]]), t in Dom::Interval([0], [1]), matrix([[- 2.2916666666666666666666666666667*t^5 + 6.4583333333333333333333333333333*t^4 - 4.1666666666666666666666666666667*t^3 - 0.0000000000000062172489379008766263723373413086], [0], [1.5208333333333333333333333333333*t^5 - 5.1041666666666666666666666666667*t^4 + 4.5833333333333333333333333333333*t^3 + 0.00000000000000088817841970012523233890533447266]]))
and VEL and ACC are similar with different values (coeffiecents) only.
The ODE45 function is like that:
function output=PID5DOF4(t,D)
x=D(1);
y=D(2);
z=D(3);
.
.
.
.
qld=POS;
qldotd=VEL;
qlddot=ACC;
.
.
.
xddot=A*qld+B*qldotd;
yddot=C*qldotd+D*qldotd;
zddot=E*qlddotd+F*qldotd;
output=[xddot yddot zddot]';
NOTE THAT,
POS, VEL, ACC are function of time, so we need to substitute the time (t) at each time step in the solution to find qld, qldotd, qlddotd.
  4 commentaires
Hassan Alkomy
Hassan Alkomy le 10 Mai 2020
I found that I need to factorize my matrix into vectors and then use interp1.
Thank you.
Hassan Alkomy
Hassan Alkomy le 10 Mai 2020
Follow up,
interp1 also accepts matrices as input argument, so I do not need to factorize the matrix.
Actually your answer is an essential part of the solution. I would say that this is also an accepted answer.
Thank you again.

Connectez-vous pour commenter.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 10 Mai 2020
See these two examples of ode45 to learn how to deal with time-dependent parameters and load external variable inside the ode function
  2 commentaires
Hassan Alkomy
Hassan Alkomy le 10 Mai 2020
This one works well.
Thank you.
Ameer Hamza
Ameer Hamza le 10 Mai 2020
I am glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by