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
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