所以,我试图在Matlab上优化这个代码,我能做的唯一事情(我认为)就是对它进行矢量化。问题是我在矢量化代码中找到的所有指南都是针对非常简单的问题,所以我不知道是否可以对此进行矢量化。
h = zeros(1,length(t));
n = zeros(1,length(t));
b = zeros(1,length(t));
z = zeros(1,length(t));
V = zeros(1,length(t));
I = zeros(1,length(t));
delta_t = t(2) - t(1);
% Initial conditions
h(1) = 0.978936;
n(1) = 0.0244296;
b(1) = 0.205115;
z(1) = 0.00139361;
V(1) = -71.8723;
for i=1:(length(t)-1)
h(i+1) = h(i) + delta_t*feval(@h_prime,V(i),h(i));
n(i+1) = n(i) + delta_t*feval(@n_prime,V(i),n(i));
b(i+1) = b(i) + delta_t*feval(@b_prime,V(i),b(i));
z(i+1) = z(i) + delta_t*feval(@z_prime,V(i),z(i));
minf = m_inf(V(i));
pinf = p_inf(V(i));
ainf = a_inf(V(i));
if (t(i) >= t_app(1) && t(i) <= t_app(2))
I(i) = Iapp;
else I(i) = 0;
end;
V(i+1) = V(i) + delta_t*feval(@V_prime,V(i),h(i),n(i),b(i),z(i),minf,pinf,ainf,I(i));
end;
任何帮助将不胜感激。
编辑:所有的功能都是功能,最复杂的功能是V_prime:
function dV = V_prime(V, h, n, b, z, minf, pinf, ainf, Iapp)
% membrane potential (µF/cm^2)
Cm = 1;
% reverse potentials (mV)
EL = -70;
ENa = 55;
EK = -90;
% maximum conductances (mS/cm^2)
gL = 0.05;
gNa = 35;
gNaP = 0.20; % varies between 0-0.41
gKdr = 6;
gA = 1.4;
gM = 1;
% ionic currents
INa = gNa*(minf^3)*h*(V-ENa);
INaP = gNaP*pinf*(V-ENa);
IKdr = gKdr*(n^4)*(V-EK);
IA = gA*(ainf^3)*b*(V-EK);
IM = gM*z*(V-EK);
IL = gL*(V-EL);
dV = (-(INa + INaP + IKdr + IA + IM + IL) + Iapp)/Cm;
这是h_prime
function dh = h_prime(V, h)
h_inf = 1/(1+exp((V+45)/7));
T_h = 0.1+0.75*(1/(1+exp((V+40.5)/6)));
dh = (h_inf - h)/T_h;