Matlab Help Input argument undefined

  • Context: MATLAB 
  • Thread starter Thread starter matlabphd
  • Start date Start date
  • Tags Tags
    Argument Input Matlab
Click For Summary
SUMMARY

The forum discussion addresses an error encountered while using the ODE45 solver in MATLAB, specifically the "Input argument 'y' is undefined" message. The user provided a function named 'lvv' that implements the Lotka-Volterra equations but failed to pass the required input arguments correctly. The solution involves ensuring that both 't' and 'y' are defined when calling the ODE45 function, which is crucial for the function to execute without errors.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with ODE45 solver in MATLAB
  • Basic knowledge of Lotka-Volterra equations
  • Experience with function input arguments in MATLAB
NEXT STEPS
  • Review MATLAB documentation on ODE45 function usage
  • Study examples of defining and passing function arguments in MATLAB
  • Learn about the Lotka-Volterra model and its applications
  • Explore debugging techniques for MATLAB code to identify input errors
USEFUL FOR

Mathematics students, researchers working with differential equations, and MATLAB users seeking to solve ordinary differential equations using the ODE45 solver.

matlabphd
Messages
2
Reaction score
0
Dear all. I am trying to solve an ODE in MATLAB using ODE45 solver. But the programe keep saying

? Input argument "y" is undefined.

Error in ==> lvv at 4
yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];

Can anybody be of help? Please.

The complete code is this:
function yprime=lvv(t,y)
%LV: Contains Lotka-Volterra equations
a=.5471;b=.0281;c=.0266;r=.8439;
yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];
[t,y]=ode45(@lvv,[0 20],[30;4])
plot(t,y(:,1))
Thanks
 
Physics news on Phys.org
matlabphd said:
Dear all. I am trying to solve an ODE in MATLAB using ODE45 solver. But the programe keep saying

? Input argument "y" is undefined.

Error in ==> lvv at 4
yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];

Can anybody be of help? Please.

The complete code is this:
function yprime=lvv(t,y)
%LV: Contains Lotka-Volterra equations
a=.5471;b=.0281;c=.0266;r=.8439;
yprime=[a*y(1)-b*y(1)*y(2);-r*y(2)+c*y(1)*y(2)];
[t,y]=ode45(@lvv,[0 20],[30;4])
plot(t,y(:,1))
Thanks

When you call the function do you provide the matrices t and y? If not, the function does not know what y is.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K