How can I use values from datafile as a time dependent function in ODE system?
Afficher commentaires plus anciens
Hi and thanks in adcance for the help.
I'm trying to solve an ODE system in which one equation takes a torque function as an input. However I do not have the torque as a function but as a dataset with measured values from a test bench (26600 values, timestep is 1/100 s). When I pass a simple time dependent function as the torque everything works as expected. I'm just having trouble figuring out how to define my values as a proper function.
My code for the ODE looks somewhat like this (simplified for simplicities sake):
function dy = f(t,y)
global a b c;
dy = zeros(4,1);
dy(1) = y(2);
dy(2) = a.* y(2) - b .* y(1) - y(4) .* cos(y(3));
dy(3) = y(4);
dy(4) = - c .* y(4) .*cos(y(3))^2 - (a+b) .* sin(y(3)) .* cos(y(3)) - myTorque(t)./b;
end
When I define a function myTorque(t) like the following I get the results I want:
function torque = myTorque(t)
torque = 100*exp(t/50);
end
However I don't know how to use the values from a datafile. I read the values like this:
load('D:\path\datafile.mat');
t_VL = datafile.act_torque_1.data;
t_VR = datafile.act_torque_2.data;
t_HL = datafile.act_torque_3.data;
t_HR = datafile.act_torque_4.data;
global torque; torque = t_VL + t_VR + t_HL + t_HR;
This leaves me with torque as a 26600x1 double. How can I make this work as a time dependent function for the ODE in place of the myTorque(t) function?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!