Your error message says you have the line
[t,x] = ode15s(@(t,x) hindmarsh_rose, tspan, x0);
but the code you posted has the line
[t,x] = ode15s(@(t,x) hindmarsh_rose(x,u), tspan, x0);
You did not post the code for the same version that you executed. The version that you posted, with the (x,u) would not produce the error message that you indicate.
However, line 1 of try1 establishes u as a row vector of length 501. Your code inside the hindmarsh_rose function includes the line
F = [Y-X.^3+3*X.^2-Z+u;1-5*X.^2-Y;0.001*(4*(X-(-1.618))-Z)];
The first component of that list, Y-X.^3+3*X.^2-Z+u, uses u and so would give a row vector of length 501 as its value. The second component of the list, 1-5*X.^2-Y, and the third component of the list, 0.001*(4*(X-(-1.618))-Z), do not use u, and so are going to give scalars. So your [] operation is going to try to do [1 x 501; 1 x 1; 1 x 1] which is going to fail because the number of columns is not the same for the ";" operation. If you were to code,
F = [Y-X.^3+3*X.^2-Z+u.';1-5*X.^2-Y;0.001*(4*(X-(-1.618))-Z)];
then that would give [501 x 1; 1 x 1; 1 x 1] which could succeed, giving a 503 x 1 output. However, that would then promptly fail because the number of values in the vector, 503, would not match the number of values in x0, namely 3.
My guess at what you want is
u =0:0.01:5;
x0 = [0.1,0.1,0.1];
tspan = [0 25];
for K = 1 : length(u)
[t,x] = ode15s(@(t,x) hindmarsh_rose(x,u(K)), tspan, x0);
plot(t,x);
hold on
end
Best Answer