MATLAB: Ode45 function Not enough input arguments error.

differential equations errornot enough arguments errorode23ode45ode45 error

Hello,
I copied a simple tutorial online on how to use an ode45 function. I have checked and double checked everything. I am going insane 🙂 Any help would be greatly appreciated. I continuously receive the error:
*NOTE: I am a novice at MATLAB
if true
>> Animate
Error using Animate (line 5)
Not enough input arguments.
end
Here is my code:
if true
function xdot = Animate(t,x)
xdot = zeros(3,1);
xdot(1) = x(2) * x(3);
xdot(2) = -x(1) * x(3);
xdot(3) = -0.51 * x(1) * x(2);
[t,x] = ode45('Animate',[0 12], [0 1 1], options);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
end

Best Answer

FYI the doc says 1st argument to ode45 is supposed to be a function handle, not a string (although a string also seems to work). Try this:
[t,x] = ode45(@Animate,[0 12], [0 1 1], options);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
It looks like the error you are getting is because you are typing in Animate without any arguments.
In any event, I get this plot by typing in the above two lines with your Animate.m function: