Matlab ode45. How to change a parameter inside it during its call?

I am new to Matlab. I hope you can help me. I have to solve the ODE system using the ODE45 function. Here is the function that describes my rules.

function dNdt = rateEquations(t, y) %populations of corresponding state Ng = y(1); Ns = y(2); Nt = y(3); %All constants used are dropped for the sake of easy reading. 

Pay attention to parameter F.

  %rate equations dNs = s0 * Ng * F - Ns/ t_S1; dNt = Ns / t_ISC - Nt / t_T1; dNg = -dNt - dNs; dNdt = [dNg; dNs; dNt]; end 

Then, in my script.m file, I call the ode45 function in 'for loop'. During each iteration, I need to change the F parameter and pass it to my "rateEquations" function. But I do not know how to implement this.

 for T = Tmin: dt : Tmax %initial conditions initialConditions = [N0 0 0]; timeSpan = [T T+dt]; 

before calling ODE45 F should be changed.

  [t,N] = ode45('rateEquations', timeSpan, initialConditions) 

etc.

 end 

Thanks in advance.

+6
source share
1 answer

You want to make the F argument of your derived function and pass the correct anonymous function to ode45 :

 [t,N] = ode45(@(t,y) rateEquations(t,y,F), timeSpan, initialConditions) 
+7
source

Source: https://habr.com/ru/post/898795/


All Articles