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 个评论
Walter Roberson
2019-5-29
What shows up for
which -all ode45
Note: we recommend you use
[t, x] = ode45(@step2, tspan, ic);
回答(1 个)
Star Strider
2019-5-29
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 个评论
Walter Roberson
2019-5-29
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!