Matlab ode45。如何在调用它时更改其中的参数? [英] Matlab ode45. How to change a parameter inside it while calling it?

查看:1000
本文介绍了Matlab ode45。如何在调用它时更改其中的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Matlab新手。我希望你能帮助我。
我必须使用ODE45函数来解决一个ODE系统。

 函数dNdt = rateEquations(t,y)
%相应的群体状态
Ng = y(1);
Ns = y(2);
Nt = y(3);

%为便于阅读,所使用的所有常量均被删除。

记下参数F.

 %速率方程
dNs = s0 * Ng * F - Ns / t_S1;
dNt = Ns / t_ISC - Nt / t_T1;
dNg = -dNt - dNs;

dNdt = [dNg; DNS; DNT];

end

然后,在我的脚本.m文件中,我打电话给ode45函数在'for循环'中。在每次迭代中,我必须更改参数F并将其传递给我的'rateEquations'函数。但我不知道如何实现它。

 对于T = Tmin:dt:Tmax 
%初始条件
initialConditions = [N0 0 0];
timeSpan = [T T + dt];

在调用ODE45之前F将被更改。

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

等等...

  end 

预先感谢您。 code> F 您的派生函数的参数,并将正确的匿名函数传递给 ode45



$ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ c>


I'm new with Matlab. I hope you can help me. I have to solve a system of ODEs using ODE45 function. 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.

  %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 have to change the parameter F and pass it to my 'rateEquations' - function. 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.

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

and so on ...

end

Thanks in advance.

解决方案

You want make F an argument of your derivative function and pass the right anonymous function to ode45:

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

这篇关于Matlab ode45。如何在调用它时更改其中的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆