Not enough input arguments
3 views (last 30 days)
Show older comments
Hi,
I put the below code in, and I get this error:
>> odefcn
Not enough input arguments.
Error in odefcn (line 3)
dydt(1)=y(2);
I have tried other similar examples from text books and get the same error. What could it be?
Thanks
function dydt=odefcn(t,y,A,B)
dydt=zeros(2,1);
dydt(1)=y(2);
dydt(2)=(A/B)*t.*y(1);
A=1;
B=2;
tspan=[0 5];
y0=[0 0.01];
[t,y]=ode45(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.')
end
0 Comments
Accepted Answer
Steven Lord
on 1 Nov 2019
Do not put the ode45 call inside the same function you're passing into ode45. At best you receive an error like the one you received; near worst you receive an error about the recursion limit; worst case scenario you've increased your recursion limit too high and crash MATLAB.
These lines should be written in the MATLAB Command Window or as part of a separate script or function.
A=1;
B=2;
tspan=[0 5];
y0=[0 0.01];
[t,y]=ode45(@(t,y) odefcn(t,y,A,B), tspan, y0);
plot(t,y(:,1),'-o',t,y(:,2),'-.')
These lines should be part of your odefcn function.
function dydt=odefcn(t,y,A,B)
dydt=zeros(2,1);
dydt(1)=y(2);
dydt(2)=(A/B)*t.*y(1);
end
You don't call odefcn directly. You pass it into ode45 which calls it with the input arguments ode45 deems necessary to solve the ODE.
More Answers (0)
See Also
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!