Why can't I use the ode45 function?

The picture is a script and the content below is a command window.
Why can't I use the ode45 function?... only my computer has the error ,,ToT
>>Report
Error occurred during use: ode45
Too many input arguments.
Error occurred: report (line 7)
[t,x] ode45('step2'tspan,ic);
this is the Command Window
Why can't I use the ode45 function?

1 comentario

What shows up for
which -all ode45
Note: we recommend you use
[t, x] = ode45(@step2, tspan, ic);

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 29 de Mayo de 2019
The function you posted is called ‘step’, not ‘step2’. (The ’step’ function is the name of several built-in MATLAB functions. Always check to be certain you have not done that with respect to your functions or variables. This is called ‘overshadowing’ of built-in MATLAB functions, and is to be strictly avoided.)
First, rename your function ‘step2’, and save it as ‘step2.m’.
Then, try this:
[t,x] = ode45(@step2, tspan, ic);
Note that this uses the function handle reference to your function.

1 comentario

Walter Roberson
Walter Roberson el 29 de Mayo de 2019
In MATLAB the first function in a file is to be called according to the filename, not according to the function name, in case of a disagreement. As the file is step2.m it is acceptable to MATLAB to use a different function name inside step2.m . It is, though, confusing to the reader.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Mayo de 2019

Comentada:

el 29 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by