Borrar filtros
Borrar filtros

Error "Not enough Input Arguments" in predator-prey model

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 3 de En. de 2018
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')
  3 comentarios
Star Strider
Star Strider el 4 de En. de 2018
@summyia qamar — My pleasure.
@Walter — Thank you.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 3 de En. de 2018
The way you give your code makes it appear as if all of your code is within predPrey.m and that your call to ode45 is on line 3 of predPrey.m and that you try to run the ode by executing the predPrey file. If so then you need to break out the line starting from [t,xa] into a different file. Or, if you are running R2016b or later, you could use one file that is not named prepPrey.m that contains
[t,xa] = ode45(@predPrey,[0 1.5],[0 1/2 3]);
plot(t,xa(:,2))
title('y(t)')
xlabel('t'), ylabel('y')
function f=predPrey(t,x)
f=[-x(1)+3*x(3);-x(2)+2*x(3);x(1)^2-2*x(3)];
The alternative to all of this is to use just one file containing:
prePrey = @(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')

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by