Not enough input arguments
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Steven Lord
2019-11-1
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!