I am trying to code an ODE system for $n=[-2,-1,0,1]$
$\frac{dx_n}{dt}=V_nx_n-x_{n+1}-x_{n-1}$
with some IC, say $[0 ~ 0~ 0~0]$: I have also a B.C at the two ends $n=-2$ and $n=1$, which I don't know how to implement at the moment, so to start I just tried to code with only I.Cs but having some problem. The code is
tic;
x0 = [0 0 0 0];
tspan = [0, 2];
V=-2.5;
eoms = @(t,x) [V*x(1)-x(2); V*x(2)-x(3)-x(1); V*x(3)-x(4)-x(2); V*x(4)-x(5)-x(3)];
[t, x] = ode45(eoms, tspan, x0)
toc
plot(t,x)
where x(1) corresponds to $x_{-2}$ , x(2) corresponds to $x_{-1}$ and so on, for the four equations corresponding to $n=-2,-1,0,1$. The term $x_{-3}$ has been ignored. The code gives some errors "Index exceeds matrix dimensions."