ODE45 function Error "called with incorrect number of arguments"

Can somebody help me with this please?? I keep getting this error message and I don't know what I'm doing wrong.
function dx = eom(t,x)
m = 2;
l_1 = 20;
l_2 = 18;
k = 300;
g = 9.8;
dx(1,1) = x(2)
dx(3,1) = x(4)
dx(2,1) = (x(1)*(m*(l_1*(x(2)^2)-g)-k*l_1)+k*l_2*x(1))/(m*l_1)
dx(4,1) = (x(2)*(m*(l_2*(x(4)^2)-g)-k*l_2)+k*l_1*x(3))/(m*l_2)
end
---------------------------
x0 = [1, 2, 1, 2]; %initial conditions
tspan = [0,30];
[t,x] = ode45('eom', tspan, x0)
plot(t,x(:,1))
-----------------------------
Error using odearguments (line 87)
Simulink model 'eom' was called with incorrect number of arguments
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Lab5 (line 3)
[t,x] = ode45('eom', tspan, x0)

Answers (1)

There happens to be a Simulink Control Systems demo named 'eom'.
If you look at https://www.mathworks.com/help/matlab/matlab_prog/function-precedence-order.html then loaded simulink models have priority over functions in the same directory or other directories.
When the path is examined, within any one folder, simulink models have higher priority than anything other than built-in functions or mex functions.
You could take care to clear eom (so it would no longer be loaded) and then to re-arrange your MATLAB path so that toolbox/slcontrol/slctrldemos was lower priority than where you have your eom.m
Or you could rename your eom.m to something else.
Note: Unless you are using MATLAB 5.0 or earlier, it is recommended that you change
[t,x] = ode45('eom', tspan, x0)
to
[t,x] = ode45(@eom, tspan, x0)

Categories

Find more on Reporting and Database Access in Help Center and File Exchange

Asked:

on 9 Mar 2017

Edited:

on 9 Mar 2017

Community Treasure Hunt

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

Start Hunting!