We cannot test that without Faero and Fric
Your error message is against a line number which exceeds the number of lines of code you show us.
You should be parameterizing the function rather than counting ode45 to pass extra parameters to the function. That behaviour of ode45 has not been documented for over a decade, having been functionally replaced as of MATLAB 5.1.
[t,x]=ode45(@(t,x) sisedo(t,x,N,theta,mu,gamma,kappa,ka,ca),tspan,x0,opciones);
For efficiency your sisedo should be pre-allocating the output instead of growing the output variable.
function dzdt = sisedo(~,x,N,theta,mu,gamma,kappa,ka,ca)
dzdt = zeros(6*N,1);
for i=1:N
j=(i-1)*6+1;
dzdt(j:j+5) = [
x(j+1)
(-kappa*(2*x(j)-x(j+6))-(x(j)-x(j+2)-theta*x(j+4)))/mu
x(j+3)
-(x(j+2)-x(j)-theta*x(j+4))-Faero(x(j+2),x(j+3),ca,ka)
x(j+5)
(-(2*theta*x(j+4)-x(j+2)+x(j))-Fric(x(j+4),x(j+5),i))/(theta*gamma)];
end
end
As for the out of range:
Your x is defined as being 6*N long. Look at the behaviour when i reaches N in the for loop. j will become (N-1)*6+1 so with N = 10 that would be j = 55, allowing for x(j) = x(55), x(j+1) = x(56), x(j+2) = x(57), x(j+3) = x(58), x(j+4) = x(59), x(j+5) = x(60) . With x being 60 long, x(j+6) = x(61) will not exist. But you have
(-kappa*(2*x(j)-x(j+6))-(x(j)-x(j+2)-theta*x(j+4)))/mu
which refers to x(j+6) so that is always going to be out of bounds when i is maximum. You need to recheck your equations there to figure out why that one term is referring to the "next" group of x values.