Error Message Using ODE45

1 view (last 30 days)
Eugene Dirk
Eugene Dirk on 13 Dec 2019
Commented: darova on 17 Dec 2019
The following code was copied directly from MatLab ODE45 documentation into MatLab script:
function dydt = vdp1(t,y)
%VDP1 Evaluate the van der Pol ODEs for mu = 1
% See also ODE113, ODE23, ODE45.
% Copyright 1984-2014 The MathWorks, Inc.
dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];
[t,y] = ode45(@vdp1,[0 20],[2; 0]);
plot(t,y(:,1),'-o',t,y(:,2),'-o')
The error message received from RUN execution is:
>> vdp1
Not enough input arguments.
Error in vdp1 (line 7)
dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];
Is there a solution or work around for this issue?

Answers (4)

Walter Roberson
Walter Roberson on 14 Dec 2019
The part starting from
[t,y] = ode45(@vdp1,[0 20],[2; 0]);
plot(t,y(:,1),'-o',t,y(:,2),'-o')
Should be in a different file that is the one to be run.

Eugene Dirk
Eugene Dirk on 14 Dec 2019
Hello,
The proposed solution did not work; no other 'y' was found in the directory. The function defined in the original message was placed in a directory by itself and results of execution (free from any 'y' ) failed. After some some rework of the MatLab code, the following solution (below) produced the correct results.
function vdp1
%VDP1 Evaluate the van der Pol ODEs for mu = 1
%
% See also ODE113, ODE23, ODE45.
% Copyright 1984-2014 The MathWorks, Inc.
[t,y] = ode45(@(t,y) [y(2); (1-y(1)^2)*y(2)-y(1)], [0 20],[2; 0]);
plot(t,y(:,1),'-o',t,y(:,2),'-+')
Thank you for your prompt response to my problem. With the work around above, the class of problems I will be working on can be handled satisfactorily.

Eugene Dirk
Eugene Dirk on 15 Dec 2019
Heloo Walter,
Thanks for your suggestion-unfortunately, it did not work. However, I rewrote the MatLab code, shown below, that did execute successfully.
function vdp1
%VDP1 Evaluate the van der Pol ODEs for mu = 1
%
% See also ODE113, ODE23, ODE45.
% Copyright 1984-2014 The MathWorks, Inc.
[t,y] = ode45(@(t,y) [y(2); (1-y(1)^2)*y(2)-y(1)], [0 20],[2; 0]);
plot(t,y(:,1),'-o',t,y(:,2),'-+')
Again, thanks for the input.
Gene

Eugene Dirk
Eugene Dirk on 17 Dec 2019
Hello,
Unfortunately, the suggested resolutions to the problem I posed did not work. I supplied the solution that finally resolved the issue with ode45 that was encountered in my particular case.
Again, thanks to everyone who provided suggestions for solving my problem. I understand that not every suggestion works, but please keep trying to help people like myself that encounter MatLab issues.
Gene

Tags

Community Treasure Hunt

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

Start Hunting!