Matlab ode45基本设置

时间:2012-10-04 05:05:00

标签: matlab error-handling initialization syntax-error

我正试图用ode45模拟神经元的Morris-Lecar模型。

我在初始化ode45电话时遇到问题,而且文档无法帮助我。我知道我必须通过函数调用ode45,并从我的主脚本中调用该函数。

我对ODE的掌握有限,似乎无法理解初始化ODE45调用所需的语法。

另外,我被指示使用变量'pulse'的时间范围,但是在从主要输入的函数中没有时间范围的输入(这似乎是变量,不是固定的)脚本并将其与另一个函数一起发送到ode45函数。输入ode45的函数也有时间输入,但我再也无法弄清楚如何输入时间范围。说明非常明确,主脚本中使用的函数不接受任何时间变量。

如果你能指出我在初始化过程中发生的任何明显错误,我们将非常感激。

当前(下方)版本的错误代码如下:

Error using ODEequation (line 89)
Not enough input arguments.

Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ODEquestion (line 32)
[t Vm]=ode45(@ODEequation,[-20 20],[-30, 0.1]',[],constants, stim_on, stim_off, amp);

Error in YoonS_Lab3_EBME308_Fall2012 (line 355)
[t Vm] = ODEquestion(20,100,30)

我认为这可以追溯到我不存在且需要的时间输入。

问题涉及

Cm * dVm / dt = -Gm(Vm-Vrest) - Gca Minf (Vm - Eca) - Gk w(Vm - Ek) + pulse(t)

dw/dt = (wInf - w) / Tau-w;

wInf = (1+tanh(Vm/30)) / 2;
mInf = (1+tanh(Vm+1)) / 2;
Tau-w = 5/ (cosh(Vm/60));
Cm = membrane leakage capacticance;
Gm = membrane leakage conductance;
Vm = membrane voltage;
Vrest = membrane voltage @ neuron resting
Gca = max Ca conductance through membrane
Gk = max K conductance through membrane;
mInf refers = P ( Ca ion channel open )
wInf refers = P ( K ion channel open )
Tau-w = rate which K channels respond to change in membrane voltage
Eca = reversal potential of Ca
Ek = reversal potential of K
pulse(t) = stimulus applied to neuron
pulse(t) = A (stim-on <= t <= stim-off) or 0 (else);

作为变量。

我创建了一个发送到ode45的函数,如下所示。

function dy = ODEequation(t, Vm, w, constants, stim_on, stim_off, amp)

wInf = (1 + tan(Vm / 30)) / 2
mInf = (1 + tan((Vm + 1)/ 15)) / 2
tauW = 5/ (cosh(Vm/60))

pulse = amp * ((stim_on < t ) - ( t >= stim_off));

dy(1) = y(1) * ((-constants(2) - constants(4) * constants(9) - constants(5) * y(2)) + (constants(2) * constants(3) + constants(6) * constants(4) * constants(9) + constants(5) * y(2) * constants(7) + constants(11))) / constants(1) ;
dy(2) = = ( constants(8) - y(2) )/constants(10)
dy = dy'

和传递的函数如下

function [t Vm] = ODEquestion(stim_on, stim_off, amp)

%i)
Cm = 1;
Gm = 0.5;
Vrest = -50;
Gca = 1.1;
Gk = 2;
Eca = 100;
Ek = -70;

%ii)
Vm(1) = -30;
w(1) = 0.1;

%iii)
wInf = (1 + tan(Vm / 30)) / 2
mInf = (1 + tan((Vm + 1)/ 15)) / 2
tauW = 5/ (cosh(Vm/60))


IC1 = Vm(1) % = -30
IC2 = w(1) % = 0.1

pulse = amp %* ((stim_on < t ) - ( t >= stim_off));

constants = [Cm , Gm, Vrest, Gca, Gk, Eca, Ek, wInf, mInf, tauW, pulse];

[t Vm]=ode45(@ODEequation,[-20 20],[-30, 0.1]',[],constants, stim_on, stim_off, amp);

1 个答案:

答案 0 :(得分:1)

来自help ode45

  

ODE45求解非刚性微分方程,中序方法。

[TOUT,YOUT] = ODE45(ODEFUN,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates 
the system of differential equations y' = f(t,y) from time T0 to TFINAL 
with initial conditions Y0. ODEFUN is a function handle. For a scalar T
and a vector Y, ODEFUN(T,Y) must return a column vector corresponding 
to f(t,y). 

因此函数ODEFUN只需要两个输入(ty),而您的函数需要7个输入。

您可以按照this sitethis question上的说明解决此问题:

wrapper = @(t,Vm) ODEequation(t, Vm, w, constants, stim_on, stim_off, amp);
[t Vm]=ode45(wrapper, [-20 20],[-30, 0.1]',[],constants, stim_on, stim_off, amp);
例如,通过创建一个小包装函数来传递所有常量,同时转发由ode45插入的变量。