error solving stiff ODE system with ode15s

22 ビュー (過去 30 日間)
Elad Oz
Elad Oz 2017 年 8 月 6 日
コメント済み: Elad Oz 2017 年 8 月 8 日
the "Not enough input arguments" error pops up every time I run my code, the idea is that N is the spatial coordinate, and I am trying to solve the time dependency for every discrete point in space at a time, the equation for each point in space depends on the solutions for all the points before it, here is my attempt at it:
tspan=[0 logspace(1,5)];
y0=zeros(length(N));
[t,y]=ode15s(odelad,tspan,y0);
where odelad is in a separate .m file:
function dydt=odelad(t,y)
D0=5.8e-11;
IUV=1;
n=30;
sig_g=1;
alpha_G=IUV*D0;
R=3e-17;
N=logspace(17,23);
for i=1:length(N)
N_(i)=n*sum(y(1:i));
end
dydt=(R*n).*(1-2.*y)-(alpha_G/2).*f_DB96(N_)*exp(-sig_g.*N);
also f_DB96(N) is a separate function saved in the same folder, but it didn't even get that far and the erorr I keep getting:
Not enough input arguments.
Error in odelad (line 11)
N_(i)=n*sum(y(1:i));
Error in tester (line 27)
[t,y]=ode15s(odelad,tspan,y0);
help please !

採用された回答

Walter Roberson
Walter Roberson 2017 年 8 月 6 日
Change to
[t,y]=ode15s(@odelad,tspan,y0);
  2 件のコメント
Jan
Jan 2017 年 8 月 6 日
編集済み: Jan 2017 年 8 月 6 日
@Elad Oz: If this is not clear immediately: Your code ode15s(odelad,tspan,y0) includes a call of the function odelad() without input arguments, while Walter's code provides a handle to the function as 1st input to ode15s. The error message mentions the problem clearly and you can use the debugger to find the reason by your own: Set a breakpoint in the failing line and type in the input arguments in the command line, until you understand, what's going on.
Elad Oz
Elad Oz 2017 年 8 月 8 日
understood, thank you both ! In my search for an answer i did come across the concept of a function handle but couldnt really understand what it is, I also found out putting the name of the function as a string also works. Could you maybe give a little explanation as to what a function handle is and if there is a connection to the fact that a string also worked or is that just another form of input the function accepts?

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

その他の回答 (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