ode45 function Not enough input arguments error.

Hello,
I copied a simple tutorial online on how to use an ode45 function. I have checked and double checked everything. I am going insane :) Any help would be greatly appreciated. I continuously receive the error:
*NOTE: I am a novice at MATLAB
if true
>> Animate
Error using Animate (line 5)
Not enough input arguments.
end
Here is my code:
if true
function xdot = Animate(t,x)
xdot = zeros(3,1);
xdot(1) = x(2) * x(3);
xdot(2) = -x(1) * x(3);
xdot(3) = -0.51 * x(1) * x(2);
[t,x] = ode45('Animate',[0 12], [0 1 1], options);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
end

댓글 수: 2

Susie
Susie 2013년 10월 2일
By the way, the 'if true' and 'end' statements at the beginning and end of my code are just part of the way this comment box formatted my code. Couldn't get rid of them. Those lines are not in my actual MATLAB code.
Thanks
Susie
Susie 2013년 10월 2일
One more thing: my line 5 is 'xdot(1) = x(2) * x(3);'

댓글을 달려면 로그인하십시오.

 채택된 답변

James Tursa
James Tursa 2013년 10월 3일
편집: James Tursa 2013년 10월 3일

1 개 추천

FYI the doc says 1st argument to ode45 is supposed to be a function handle, not a string (although a string also seems to work). Try this:
[t,x] = ode45(@Animate,[0 12], [0 1 1], options);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
It looks like the error you are getting is because you are typing in Animate without any arguments.
In any event, I get this plot by typing in the above two lines with your Animate.m function:

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 2일

1 개 추천

Your code is correct. Can you precise where is line 5

댓글 수: 4

Susie
Susie 2013년 10월 2일
My line 5 is xdot(1) = x(2) * x(3);
Susie
Susie 2013년 10월 2일
I have no idea what I am doing wrong. I keep receiving that error message.
Check if the right function Animate is in the current folder.
Susie
Susie 2013년 10월 2일
I have checked, it is in the current folder. :(

댓글을 달려면 로그인하십시오.

Susie
Susie 2013년 10월 3일

0 개 추천

James,
I made that change, but still had the same error. So, I created an x row vector x = [1 5 10]. I'm getting different errors now. Can you post your changes because I'm not getting a plot at all.
Thanks
if true
function xdot = Animate(t,x)
xdot = zeros(3,1);
x = [1 5 10]
xdot(1) = x(2) * x(3);
xdot(2) = -x(1) * x(3);
xdot(3) = -0.51 * x(1) * x(2);
[t,x] = ode45(@Animate,[0 12], [0 1 1]);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
end

댓글 수: 4

I have a file called Animate.m in my current directory, which is:
function xdot = Animate(t,x)
xdot = zeros(3,1);
xdot(1) = x(2) * x(3);
xdot(2) = -x(1) * x(3);
xdot(3) = -0.51 * x(1) * x(2);
end
I then type in the following two lines at the command line (your options variable deleted from the call since you didn't specify what it was) and I get the plot:
[t,x] = ode45('Animate',[0 12], [0 1 1]);
plot(t,x(:,1), '-',t,x(:,2),'-.',t,x(:,3),'.')
Susie
Susie 2013년 10월 3일
<3333333333 !!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you!
Joaquim
Joaquim 2014년 5월 22일
편집: Joaquim 2014년 5월 22일
Hi, I had the same problem when i put >> [Ti,Yi]=solver(ode1,tspan,y0), after defining tspan and y0 in the command prompt.
Anyone can help me? I send the file attached. Thank you
Joaquim
Joaquim 2014년 5월 22일
here it is

댓글을 달려면 로그인하십시오.

카테고리

질문:

2013년 10월 2일

편집:

2014년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by