Not enough input arguments. in ode45

9 Ansichten (letzte 30 Tage)
minu pilvankar
minu pilvankar am 29 Aug. 2019
Kommentiert: Steve am 25 Mär. 2020
Hi,
I am trying to run the code given as an example on mathworks website (https://www.mathworks.com/help/matlab/ref/ode45.html) for ode45 and still it is giving me the error saying : "Not enough input arguments"
This is the code:
function dydt = vdp1(m,y)
dydt = [y(2); (1-y(1)^2)*y(2)-y(1)];
[m,y] = ode45(@vdp1,[0 20],[2; 0]);
plot(m,y(:,1),'-o',m,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
I am trying this as I am developing a new code based on this template and that is not working either.
What can I do?
  4 Kommentare
Star Strider
Star Strider am 29 Aug. 2019
I changed it only to use the anonymous function version of ‘vdp1’ (and the appropriate reference to it in the ode45 call) and it ran without error:
vdp1 = @(m,y) [y(2); (1-y(1)^2)*y(2)-y(1)];
[m,y] = ode45(vdp1,[0 20],[2; 0]);
plot(m,y(:,1),'-o',m,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
The first argument to a function the ODE solvers use is the dependent variable (usually ‘t’, here ‘m’), and the second is the dependent variable, here ‘y’. The code is correct and runs without error.
We are not seeing the code that is throwing the error, so it is not possible to figure out what the problem is.
Steve
Steve am 25 Mär. 2020
Thank you--the 2nd version given by Star Strider does work on my machine. However, the 1st version does not. I believe it has to do with the name my program is stored under.
I apparently need to study the instructions for using handles.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

madhan ravi
madhan ravi am 29 Aug. 2019
[m,y] = ode45(@vdp1,[0 20],[2; 0]);
plot(m,y(:,1),'-o',m,y(:,2),'-o')
title('Solution of van der Pol Equation (\mu = 1) with ODE45');
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2')
% try the above in command window or in a separate script file
% ------------
function dydt = vdp1(m,y) % save this in a separate file named as vdp1.m
dydt = ...;
  2 Kommentare
minu pilvankar
minu pilvankar am 29 Aug. 2019
Thanks for the response! Yeah, thats what I thought coz it ran fine on my lab computer. Not sure what is wrong then.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by