ode 45 not enough input arguments
이전 댓글 표시
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
2019년 3월 5일
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
2019년 3월 5일
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
2019년 3월 5일
Star Strider
2019년 3월 5일
My pleasure.
If my Answer helped you solve your problem, please Accept it!
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!