Hi everyone, I'm trying to solve a system of 3 ODEs with intial conditions using ode45. I'm getting the error message of "Not enough input arguments". I've tried looking up what that means, but I'm still confused. If anyone could help me out with this, that would be great!
function dx=sae(t,x)
x(1) = x;
x(2)=y;
x(3) = z;
dx=zeros(3,1);
dx(1)=10*(x(2)-x(1));
dx(2)=(28*x(1))-x(2)-(x(1)*x(3));
dx(3)=(x(1)*x(2))-((8/3)*x(3));
[T,X]=ode45(@sae,[0 20],[0 1 0]);
plot(T,X(:,1),T,X(:,2),T,X(:,3))
legend('x','y','z')
end

 採用された回答

Star Strider
Star Strider 2014 年 11 月 23 日

0 投票

First, save your ‘sae’ function in its own function .m-file called sae.m.
Second, be sure the ode45 call is not within the ODE function, as it seems to be in the code you posted. That creates recursion problems.
Third, comment-out the references to the elements of ‘x’ in ‘sae’. Keep them for information, but be sure they don’t execute.
In sae.m:
function dx=sae(t,x)
% x(1) = x;
% x(2) = y;
% x(3) = z;
dx=zeros(3,1);
dx(1)=10*(x(2)-x(1));
dx(2)=(28*x(1))-x(2)-(x(1)*x(3));
dx(3)=(x(1)*x(2))-((8/3)*x(3));
end
In your script file:
[T,X]=ode45(@sae,[0 20],[0 1 0]);
plot(T,X(:,1),T,X(:,2),T,X(:,3))
legend('x','y','z')
This works, and produces an interesting plot.

4 件のコメント

Stefan
Stefan 2014 年 11 月 23 日
OK I have the file saved as sae.m, but I'm unclear as to what you mean by saving the sae function in its own function? Is that like function-ception? (Sorry for the bad joke.) I'm pretty new to MATLAB, so please excuse what might seem like dumb questions.
Star Strider
Star Strider 2014 年 11 月 23 日
If you saved your ‘sae’ function by itself (from the function statement to its own end statement) in sae.m as I listed it in my answer, you’re half way there.
All you need now is to create a script file (as its own separate .m-file) with your ode45 call in it, and run the script file. (You can name it anything you want.) Then run the script file. You should see your plot a few seconds later.
Stefan
Stefan 2014 年 11 月 23 日
Thank you very much! You are a lifesaver!
Star Strider
Star Strider 2014 年 11 月 23 日
My pleasure! Thank your for the compliment!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2014 年 11 月 23 日

コメント済み:

2014 年 11 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by