ode45 not enough input arguments error

8 ビュー (過去 30 日間)
Daniel Hunt
Daniel Hunt 2018 年 2 月 11 日
コメント済み: Daniel Hunt 2018 年 2 月 12 日
trying to solve a 2nd order ODE using ode45, i looked up several tutorials to help me as i was working through it. My code looks very similar to the tutorials with the exception of different equations and initial values.
function rk=ode45bessel(t,v)
rk=[v(2);-v(1)-(1/t)*v(2)];
t=[0:50];
initialvalues=[-4.0690e-05,-8.1380e-05];
[t,v]=ode45(@ode45bessel,t,initialvalues);
plot(t,v)
thats my code and i get an error on line 4 saying not enough input arguments

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 11 日
You need to break that into two files
function rk=ode45bessel(t,v)
rk=[v(2);-v(1)-(1/t)*v(2)];
which you store into ode45bessel.m
and the rest of the lines in a second file (with a name other than 'ode45bessel.m' or 'ode45.m') . Then you would run the second file.
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 2 月 11 日
You start at t = 0, and you have 1/t in your ode45bessel, which is leading to an infinite value there that forces the second element of the first response to be infinite. That infinite value then comes back to the very next iteration and gets carried over the first output, so you get [inf -inf] for the second iteration. That gives you -inf+inf to be integrated for the second element, which gives nan. You are lost from there.
Daniel Hunt
Daniel Hunt 2018 年 2 月 12 日
didnt even think of that, all sorted now

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by