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!