필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
summyia qamar
summyia qamar 2018년 1월 3일
댓글: Star Strider 2018년 1월 4일
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.

채택된 답변

Star Strider
Star Strider 2018년 1월 3일
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
Star Strider
Star Strider 2018년 1월 4일
@summyia qamar — My pleasure.
@Walter — Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 1월 3일
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')

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by