简体   繁体   English

Matlab ode45。调用它时如何更改其中的参数?

[英]Matlab ode45. How to change a parameter inside it while calling it?

I'm new with Matlab. 我是Matlab的新手。 I hope you can help me. 我希望你能帮助我。 I have to solve a system of ODEs using ODE45 function. 我必须使用ODE45函数来解决一个ODE系统。 Here is the function which describes my equitions. 这是描述我的等同的功能。

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.

Note the parameter F. 注意参数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'. 然后,在我的脚本.m文件中,我在'for循环'中调用ode45函数。 During each iteration i have to change the parameter F and pass it to my 'rateEquations' - function. 在每次迭代期间,我必须更改参数F并将其传递给我的'rateEquations' - 函数。 But i don't know how to realize it. 但我不知道如何实现它。

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

before calling ODE45 F is to be changed. 在调用ODE45 F之前要更改。

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

and so on ... 等等 ...

end

Thanks in advance. 提前致谢。

你想让F成为你的派生函数的一个参数,并将正确的匿名函数传递给ode45

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM