Matrix dimensions must agree.

4 visualizaciones (últimos 30 días)
Reed Woyda
Reed Woyda el 30 de Mzo. de 2016
Comentada: Walter Roberson el 31 de Mzo. de 2016
Hello all,
Writing a program to simulate neural signals and I have hit a road block.
The error occurs on this line in the code, complaining about the / sign. wdot = phi*((ninf(v)-r)*(1/(taun(v))));
I used these same equations in a runge-kutta ODE solver and they had no trouble working there..
Any ideas would be much appreciated.
Here is the function I am working in..
function udot = FN_deriv_MOL(t,u)
global Cm phi gCa ECa EK EL gK gL V1 V2 V3 V4 Iapp xu xl N
ninf = @(V) (0.5)*(1+tanh((V-V3)/V4));
minf = @(V) (0.5)*(1+tanh((V-V1)/V2));
taun = @(V) 1/(cosh((V-V3)/(2*V4)));
v=u(1:N,1);
r=u(N+1:end,1);
dx2=((xu-xl)/(N-1))^2;
for i=1:N
if(i==N)
vdot(i)=((-v(i)+v(i-1))/dx2)+(Iapp-gL*(v(i)-EL)-gK*r(i)*(v(i)-EK)-gCa*minf(v(i))*(v(i)-ECa))*(1/Cm);
elseif(i==1)
vdot(i)=((v(i+1)-v(i))/dx2)+(Iapp-gL*(v(i)-EL)-gK*r(i)*(v(i)-EK)-gCa*minf(v(i))*(v(i)-ECa))*(1/Cm);
else
vdot(i)=((v(i-1)-2*v(i)+v(i+1))/dx2)+(Iapp-gL*(v(i)-EL)-gK*r(i)*(v(i)-EK)-gCa*minf(v(i))*(v(i)-ECa))*(1/Cm);
end
end
vdot = vdot';
wdot = phi*((ninf(v)-r)*(1/(taun(v))));
udot=[vdot; wdot];
And the Program which calls this function..
clear all; close all; clc;
%
global Cm phi gCa ECa EK EL gK gL V1 V2 V3 V4 Iapp xu xl N
Cm = 20;
phi = 0.04;
gCa = 4.4;
ECa = 120;
EK = -84;
EL = -60;
gK = 8;
gL = 2;
V1 = -1.2;
V2 = 18;
V3 = 2;
V4 = 30;
Iapp = 60; %periodic = 100
N=300; % spatial grid number
xl=0;xu=300; %30;
x=linspace(xl,xu,N);
v0=[***giant array of initial conditions left out, length=300]
v0=v0';
r0(1:N,1) = 0;
u0=[v0; r0];
t0=0; tend=500;
tspan=linspace(t0,tend,200);
[t,u] = ode15s('FN_deriv_MOL',tspan,u0);
v=u(:,1:N);
r=u(:,N+1:end);

Respuestas (1)

Walter Roberson
Walter Roberson el 30 de Mzo. de 2016
The / operator does not mean the kind of division you need. You need the ./ operator.
  2 comentarios
Reed Woyda
Reed Woyda el 31 de Mzo. de 2016
Walter, Thank you for the feedback
but... When I replace the / operator with the ./ operator I get an error that the vdot and wdot vectors are not consistent.
Shouldnt they both be the same since wdot is calculated with r, which is the same size as v?
Walter Roberson
Walter Roberson el 31 de Mzo. de 2016
I recommend you do a bit of rewriting. Avoid global. Please see http://www.mathworks.com/help/matlab/math/parameterizing-functions.html . And when you call ode45, use the @FN_deriv_MOL instead of 'FN_deriv_MOL'

Iniciar sesión para comentar.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by