Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: how to connect data to system of differential equations?
Posted:
Aug 30, 2013 6:32 AM


> Hi all, > I have a system of differential equations and a > construction of different mfiles, which are connected > to each other. Now I will get a data set constiting > of values along a 1 year period or more, so the > structure is: > time = [1 2 3 4 5 6 7 8 9 10 11 12]; > datavalues = [0.2 0.3 0.5 0.9 1 1.5 1.6 2 0.7 0.6 0.3 > 0.1]; > These datavalues should influence many of the > differential equations (such as temperature), so > 'datavalues' is used as a variable in some equations. > Some other data than temperature will be rather > random and it would be hard or impossible to come up > with a formula describing the dataset. Is there a way > to do this without using Simulink? > I´d be very happy for a reply :)
You can pass the data to the function routine where you define your differential equations (here: myode) as
[T Y] = ode45(@(t,y) myode(t,y,time,datavalues),Tspan,IC);
The function myode then should look like
function dy = myode(t,y,time,datavalues) ...
In the function "myode" itself, it will be necessary to interpolate your data to the time t supplied by the solver. This can be done according to y_interpolated = interp1(time,datavalues,t) The value y_interpolated now gives an approximation to the value of your array "datavalues" at time t. Be careful with the units  t and time must have the same physical unit (e.g. seconds, minutes,...).
Good luck.
Best wishes Torsten.



