MATLAB: Error “Not enough Input Arguments” in predator-prey model

errorode45

I'm trying to understand the working of ODE45 to solve multiple variable equations. I copied a code from internet but when I run this code, matlab gives error
Not enough input arguments.
Error in predPrey (line 2)
f=[-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)];
function f=predPrey(t,x);
the code is given here:
f=[-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)];
[t,xa] = ode45(@predPrey,[0 1.5],[0 1/2 3]);
plot(t,xa(:,2))
title('y(t)')
xlabel('t'), ylabel('y')
can someone please help me in this error so I can continue modifying model for my system.

Best Answer

You did not copy it correctly or implement it correctly.
Try this:
predPrey = @(t,x) [-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)];
[t,xa] = ode45(predPrey,[0 1.5],[0 1/2 3]);
plot(t,xa(:,2))
title('y(t)')
xlabel('t'), ylabel('y')