error solving stiff ODE system with ode15s

22 views (last 30 days)
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 !

Accepted Answer

Walter Roberson
Walter Roberson on 6 Aug 2017
Change to
[t,y]=ode15s(@odelad,tspan,y0);
  2 Comments
Jan
Jan on 6 Aug 2017
Edited: Jan on 6 Aug 2017
@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 on 8 Aug 2017
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?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!