MATLAB: Not enough input arguments, ODE 45, System of ODEs

odeode45

Hello everybody! I seem to be very unlucky, I can not find any solution to my problem – I have:
Error using chu2 (line 9)
Not enough input arguments.
Here is my code:
function dy = chu2(y)
m0 = -3/7;
m1 = 4/7;
alpha = 9;
beta = 14;
dy = zeros(3,1);
dy(1) = alpha*(y(2) - y(1) - (.5)*(m0 - m1)*(abs(y(1) + 1) - abs(y(1) - 1)));
dy(2) = y(1) - y(2) + y(3);
dy(3) = -beta*y(2);
[~,Y] = ode45(@chu2,[0 1 1]);
plot3(Y)
Firstly, I thought the problem is because I gave not enough info, but I have checked everything.
Also I have a question about ODE45 – what method Matlab uses as it ? Runge–Kutta method ?* * Thank you for answering such dull question, but I am so desperate to find any mistake in my code, I have googled but that did not help.
Solution to this problem by Star Strider is to call not the chu2(y) but chu2(~,y)

Best Answer

First, it seems that you are calling your ODE function ‘chu2’ from inside the function, with these lines:
[~,Y] = ode45(@chu2,[0 1 1]);
plot3(Y)
Do not do that! Call it from outside your function, in the main script file.
Second, the ODE solvers require 3 arguments, the first one being your ODE function (that you supplied), the second one being vector containing a range [beginning end] or vector of solution times, and the third your initial conditions. It seems you omitted your time vector, the reason you got the error.
Related Question