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?

回答 (1 件)

Star Strider
Star Strider 2019 年 3 月 5 日

0 投票

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 件のコメント

YoonGyeong Jeong
YoonGyeong Jeong 2019 年 3 月 5 日
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 changed it but it still does not work
Star Strider
Star Strider 2019 年 3 月 5 日
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
YoonGyeong Jeong 2019 年 3 月 5 日
Oh it was because of the name. Thank you so much!
Star Strider
Star Strider 2019 年 3 月 5 日
My pleasure.
If my Answer helped you solve your problem, please Accept it!

サインインしてコメントする。

カテゴリ

質問済み:

2019 年 3 月 5 日

コメント済み:

2019 年 3 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by