Calling external time dependent variables inside ODE45 function

조회 수: 20 (최근 30일)
Hassan Alkomy
Hassan Alkomy 2020년 5월 10일
댓글: Hassan Alkomy 2020년 5월 10일
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
Hassan Alkomy
Hassan Alkomy 2020년 5월 10일
I found that I need to factorize my matrix into vectors and then use interp1.
Thank you.
Hassan Alkomy
Hassan Alkomy 2020년 5월 10일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 10일
See these two examples of ode45 to learn how to deal with time-dependent parameters and load external variable inside the ode function

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by