Not Enough Input Arguments

1 view (last 30 days)
Karen Melikov
Karen Melikov on 29 Oct 2015
Commented: Star Strider on 29 Oct 2015
I'm solving a third order non-linear ODE using ode45() function. My script is below. The function 'eqn' is saved in a separate file. I'm getting an error of 'Not enough input arguments.' Any help in resolving this is appreciated.
Thank you.
beta = 0;
guess = 0.4696;
eta_span = [0 5];
init_cond = [0 0 guess];
[eta, F] = ode45(eqn, eta_span, init_cond);
function F = eqn(eta_span, init_cond)
F = zeros(size(init_cond));
F(1) = init_cond(2);
F(2) = init_cond(3);
F(3) = -beta - init_cond(1) * init_cond(3) + beta * init_cond(2) * init_cond(2);

Answers (2)

Walter Roberson
Walter Roberson on 29 Oct 2015
[eta, F] = ode45(@eqn, eta_span, init_cond);

Star Strider
Star Strider on 29 Oct 2015
Edited: Star Strider on 29 Oct 2015
I didn’t run your code, but two items immediately present themselves.
First, considering that you’re letting ‘init_cond’ determine the size of the vector returned by your ODE function ‘eqn’, it must be a column vector.
Second, you need to create a function handle for ‘eqn’ using the ‘@’ operator in your ode45 call, since it is in its own function file.
See if these changes work:
init_cond = [0 0 guess]';
[eta, F] = ode45(@eqn, eta_span, init_cond);
  2 Comments
Karen Melikov
Karen Melikov on 29 Oct 2015
The init_cond vector works fine. It was the @ in front of the function handle that did it. Thanks.
I have another question, however: in my script I have a variable called beta. I would like to be able to vary beta in the script and have the function eqn take beta as an input variable. However, when I put beta in the list of eqn function variables, the code does not work. Is there a way for me to feed the beta value into the function instead of manually changing the beta value in the function? Thanks.
Star Strider
Star Strider on 29 Oct 2015
You can easily pass ‘beta’ to your ‘eqn’ function. You have to make changes in it and in your call to it in your ode45 call:
[eta, F] = ode45(@(eta_span, init_cond) eqn(eta_span, init_cond, beta), eta_span, init_cond);
function F = eqn(eta_span, init_cond, beta)

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!