Why MATLAB asks for "more input arguments" in the function which is to be handled by ode45?
Show older comments
I have following code to solve a system of differential equations
function v_out = system_ex(t,v)
v_out = zeros(2,1);
v_out(1) = v(2); % The dx/dt eq
v_out(2) = -v(1); % The dy/dt eq
[t,v] = ode45(@system_ex,[0,20],[1,1])
end
When I press Run, it gives error that not enough input arguments. However, exactly this is the syntax in the MATLAB documentation and from the source where I have taken this code (link) for ode45. Where I am lacking and why MATLAb says system_ex requires more input arguments?
1 Comment
Steven Lord
on 19 Oct 2020
Stephen Cobeldick has explained what you need to do to resolve the problem. I want to explain briefly why what you wrote didn't work.
All those lines do appear in the text of the lecture notes + assignment to which you linked, in section 2.2. However they don't appear together. The section containing the system_ex function is in the first bullet, while the call to ode45 is in the fourth.
If you had called system_ex with two inputs, it would have executed all the lines of code. This include the ode45 call which would call system_ex.
This second call to system_ex would call ode45 which would call system_ex.
This third call to system_ex would call ode45 which would call system_ex.
This fourth call to system_ex would call ode45 which would call system_ex.
... eventually MATLAB would throw an error to break the infinite loop.
Removing the ode45 call from system_ex is the right solution.
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations 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!