MATLAB Matlab Help Input argument undefined

AI Thread Summary
The discussion centers around troubleshooting an error encountered while using MATLAB's ODE45 solver to solve a system of ordinary differential equations (ODEs) defined by the Lotka-Volterra equations. The error message indicates that the input argument "y" is undefined, which suggests that the function is not receiving the necessary input parameters. The code provided defines the function and attempts to call ODE45, but it appears that the function is not being called correctly with the required arguments. To resolve this issue, it is essential to ensure that the function is invoked with the correct input matrices for time (t) and state variables (y). Properly passing these arguments will allow the ODE solver to execute without errors.
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
Views
2K
Replies
2
Views
4K
Replies
4
Views
1K
Replies
2
Views
3K
Replies
2
Views
1K
Replies
18
Views
4K
Replies
6
Views
2K
Replies
2
Views
7K
Back
Top