Calling external time dependent variables inside ODE45 function
이전 댓글 표시
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
darova
2020년 5월 10일
Did you try interp1?
Hassan Alkomy
2020년 5월 10일
Hassan Alkomy
2020년 5월 10일
Hassan Alkomy
2020년 5월 10일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!