So, I got a strange problem. Below is my code, it is a simple Euler method for integrating a Linear system of ODE's.
所以,我遇到了一个奇怪的问题。下面是我的代码,它是一个简单的Euler方法,用于集成ODE的线性系统。
function [V, h, n, b, z] = hodgkin_huxley_CA1(t, Iapp, t_app)
%function based on the CA1 pyramidal neuron model:
h = zeros(length(t));
n = zeros(length(t));
b = zeros(length(t));
z = zeros(length(t));
V = zeros(length(t));
% Initial conditions
h(1) = 0.9771;
n(1) = 0.0259;
b(1) = 0.1787;
z(1) = 8.0222e-04;
V(1) = -71.2856;
% Euler method
delta_t = t(2) - t(1);
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 = Iapp;
else 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);
end;
So, this function returns me 5 arrays, V,h,n,b and z. The problem is that if I use V(1), V(2), V(3), ..., I get the expected result. But when I tell matlab to print the whole array, I receive all values as 0. So, if I plot this array, I will get 2 curves: one that is the right one, and one that is zero. Note that this also happens to all the other variables h,n,b and z. Anyone knows what may be happening?
所以,这个函数返回5个数组,V,h,n,b和z。问题是,如果我使用V(1),V(2),V(3),...,我得到预期的结果。但是当我告诉matlab打印整个数组时,我将所有值都接收为0.因此,如果我绘制这个数组,我将得到2条曲线:一条是正确的,一条是零。请注意,这也发生在所有其他变量h,n,b和z上。谁知道可能会发生什么?
1 个解决方案
#1
1
Your outputs are meant to be vectors, however you are initializing them as square matrices.
您的输出是矢量,但是您将它们初始化为方形矩阵。
You can simply replace:
你可以简单地替换:
h = zeros(length(t));
n = zeros(length(t));
b = zeros(length(t));
z = zeros(length(t));
V = zeros(length(t));
With
同
h = zeros(length(t),1);
n = zeros(length(t),1);
b = zeros(length(t),1);
z = zeros(length(t),1);
V = zeros(length(t),1);
The zeros
function, with 1 input, creates a 2D square matrix of that dimension. With two or more inputs, it interprets the inputs as specification for all dimensions. For example:
具有1个输入的零功能创建该维度的2D方形矩阵。通过两个或多个输入,它将输入解释为所有尺寸的规格。例如:
>> x = zeros(3)
x =
0 0 0
0 0 0
0 0 0
>> x = zeros(3,1)
x =
0
0
0
#1
1
Your outputs are meant to be vectors, however you are initializing them as square matrices.
您的输出是矢量,但是您将它们初始化为方形矩阵。
You can simply replace:
你可以简单地替换:
h = zeros(length(t));
n = zeros(length(t));
b = zeros(length(t));
z = zeros(length(t));
V = zeros(length(t));
With
同
h = zeros(length(t),1);
n = zeros(length(t),1);
b = zeros(length(t),1);
z = zeros(length(t),1);
V = zeros(length(t),1);
The zeros
function, with 1 input, creates a 2D square matrix of that dimension. With two or more inputs, it interprets the inputs as specification for all dimensions. For example:
具有1个输入的零功能创建该维度的2D方形矩阵。通过两个或多个输入,它将输入解释为所有尺寸的规格。例如:
>> x = zeros(3)
x =
0 0 0
0 0 0
0 0 0
>> x = zeros(3,1)
x =
0
0
0