Why can't I use the ode45 function?
Show older comments
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 Comment
Walter Roberson
on 29 May 2019
What shows up for
which -all ode45
Note: we recommend you use
[t, x] = ode45(@step2, tspan, ic);
Answers (1)
Star Strider
on 29 May 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 Comment
Walter Roberson
on 29 May 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.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!