Error with indexing an array "Subscript indices must either be real positive integers or logicals"

Having trouble swapping different equations into a Runge-Kutta 4 ode solver for coupled equations.
Any idea as to what is going on with my index, i?
I made sure to take the ceiling of the ending value, N, but not sure what else is happening..
Subscript indices must either be real positive integers or logicals.
Error in RungeKutta4FitzhughNagumo>@(t,V,W)epsilon(V-gamma*W)
Error in RungeKutta4FitzhughNagumo (line 32)
k1W=fW(t(i) ,V(i), W(i) );
% dV/dt = f(v + veq) - f(veq) - w % Potential
% dW/dt = epsilon(v - gamma*w) % sodium gating variable
clear; clc
% constants
a=0.139;
epsilon=0.008;
gamma=2.54;
veq=0.07;
% Define function dandles
fV=@(t,V,W) (V + veq)*((V + veq)-a)*(1-(V + veq)) - veq*(veq-a)*(1-veq) - W;
fW=@(t,V,W) epsilon(V - gamma*W);
% initial conditions
t(1) = 0;
V(1) = 1;
W(1) = 1;
% Step size
h=0.1;
tfinal=50;
N=ceil(tfinal/h);
fprintf('"N = %d"',N);
% Update loop
for i=1:N
fprintf('"i = %d"',i);
%update time
t(i+1)=t(i)+h;
% Update & F
k1R=fV(t(i) ,V(i), W(i) );
k1W=fW(t(i) ,V(i), W(i) );
k2V=fV(t(i)+h/2 ,V(i)+h/2*k1V, W(i)+h/2*k1W);
k2W=fW(t(i)+h/2 ,V(i)+h/2*k1V, W(i)+h/2*k1W);
k3V=fV(t(i)+h/2 ,V(i)+h/2*k2V, W(i)+h/2*k2W);
k3W=fW(t(i)+h/2 ,V(i)+h/2*k2V, W(i)+h/2*k2W);
k4V=fV(t(i)+h/2 ,V(i)+h *k3V, W(i)+h *k3W);
k4W=fW(t(i)+h/2 ,V(i)+h *k4V, W(i)+h *k3W);
V(i+1)=V(i) + h/6*(k1R + 2*k2V + 2*k3V + k4V);
W(i+1)=W(i) + h/6*(k1W + 2*k2W + 2*k3W + k4W);
end
%plot the solution
figure(1); clf(1)
plot(t,V)
hold on
plot(t,W)
xlabel('Time')
ylabel('Populations')
legend('Rabits','Foxes')
set(gca,'FontSize',16)
Appreciate the advice!

Answers (2)

epsilon(V - gamma*W) is a request to index epsilon with subscript V - gamma*W .
Perhaps you would prefer to multiply epsilon by V - gamma*W ?

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 27 Mar 2016

Answered:

on 27 Mar 2016

Community Treasure Hunt

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

Start Hunting!