ode 45 not enough input arguments
Afficher commentaires plus anciens
function up=F(t,u)
up=zeros(2,1);
up(1)=u(2);
Epsilon = 0.2;
up(2)= -u(1)-Epsilon*((u(1)^3));
[t,u]=ode45('F',[0,20],[0,1]);
plot(t,u(:,1))
negative=find(u<0);
mu=(t(negative(1))+t(negative(1)-1)/2);
amplitude=max(abs(u(:,1)));
>>F
Not enough input arguments.
Error in F (line 3)
up(1)=u(2);
I do not know why I keep having errors like this.
Why is it not enough input?
Réponses (1)
Star Strider
le 5 Mar 2019
Create a function handle (using the ‘@’ operator) for ‘F’:
[t,u]=ode45(@F,[0,20],[0,1]);
Your code works with that change. (I also added an end call to ‘F’ in the code I used to test it.)
The single quotes no are no longer accepted for the ODE solvers.
4 commentaires
YoonGyeong Jeong
le 5 Mar 2019
Star Strider
le 5 Mar 2019
What does ‘still does not work’ mean?
This worked for me:
function up=F(t,u)
up=zeros(2,1);
up(1)=u(2);
Epsilon = 0.2;
up(2)= -u(1)-Epsilon*((u(1)^3));
end
[t,u]=ode45(@F,[0,20],[0,1]);
plot(t,u(:,1))
negative=find(u<0);
mu=(t(negative(1))+t(negative(1)-1)/2);
amplitude=max(abs(u(:,1)));
and produced a plot of a sine curve with a period of about 5.9 time units.
I ran this inside a function file I use for such purposes for MATLAB Answers problems. It would be best if you save your ODE function to its own file called F.m somewhere on your MATLAB search path. Then run your ode45 call to integrate it.
YoonGyeong Jeong
le 5 Mar 2019
Star Strider
le 5 Mar 2019
My pleasure.
If my Answer helped you solve your problem, please Accept it!
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!