Bugfixing for ode45 - "Too many input arguments"

4 visualizaciones (últimos 30 días)
Chris
Chris el 7 de Sept. de 2012
Comentada: Stephen23 el 30 de Oct. de 2020
Hey,
I am currently trying to solve a first order ODE using matlab's ode45. Here is my code:
function [ y ] = kepEQ( in )
%KEPEQ Function for ode45
y = zeros(4,1);
y(1) = in(2);
y(2) = - in(1) / (in(1)^2 + in(3)^2)^(3/2);
y(3) = in(4);
y(4) = - in(3) / (in(1)^2 + in(3)^2)^(3/2);
end
and then I call ode45 using
out = ode45(@kepEQ, [0 steps*dt], [qStart(1) pStart(1) qStart(2) pStart(2)]);
All used variables (steps, dt, qStart and pStart) have been initialized correctly, all are scalar values (well, at lest qStart(1) etc. are scalars). The error message produced by this code is:
??? Error using ==> kepEQ
Too many input arguments.
Error in ==> odearguments at 109
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
I can't really follow this error message and don't know, why it should have too many input arguments. Any help is appreciated :)

Respuestas (1)

Sean de Wolski
Sean de Wolski el 7 de Sept. de 2012
If you look in the doc for ode45 and all of the other ode solvers it shows that they need to recieve two inputs (t and y) (even if your function doesn't need both inputs).
Thus for yours, it might look like
function [ y ] = kepEQ( junk , in )
%stuff
end
  2 comentarios
Rohan Walia
Rohan Walia el 29 de Oct. de 2020
This was really helpful! Thank you!
Stephen23
Stephen23 el 30 de Oct. de 2020
Since R2009b the recommended syntax has been to use tilde to indicate unused input arguments:
function y = kepEQ(~,in)
% ^ ignore first input argument, if provided.

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by