0

I'm trying to solve an ODE in Matlab and I have the following problem: my code is as bellow:

xinit=[0.19;25;0;7];
t=0:768:76800; %% 101 cells
[t1,y]=ode45(@Model_Bio,t,xinit);

In the function @Model_Bio I have a parameter that I need to read its corresponding values for each time step (101 values)! So, My @Model_Bio is somehow as bellow:

load 'mydata'
a=mydata;    
.....

the problem is that, when I execute the ode45(@Model_Bio,t,xinit), it calls my function with an automated time step (for example 50 times!) and my problem is that I cannot assign the values for each of my time step (101)! Also, I think its not a good idea to change the time step of the ode the same as my 101 steps! Anyone that help me on this is really appreciated!

Mehrian
  • 11
  • 3

1 Answers1

1

It seems like you need to provide a wrapper of your data that interpolates it for arbitrary t, for example

my_interp = @(t) interp1(my_data_t, my_data_x, t)

http://se.mathworks.com/help/matlab/ref/interp1.html

and then implement your RHS (@Model_Bio) in terms of my_interp

alexandre iolov
  • 582
  • 3
  • 11
  • Agreed. There are plenty of similar questions like this, see for example http://stackoverflow.com/questions/26231703/solving-a-system-of-odes-where-the-functions-are-given-discrete-matlab or http://stackoverflow.com/questions/19732442/solving-an-ode-when-the-function-is-given-as-discrete-values-matlab. – am304 Jul 03 '15 at 14:29
  • 1
    it sounds like a popular question:) – alexandre iolov Jul 06 '15 at 19:31