Not enough input arguments.

3 ビュー (過去 30 日間)
Turgut Ataseven
Turgut Ataseven 2021 年 6 月 5 日
編集済み: Adam Danz 2021 年 6 月 8 日
function yp = predprey(t,y,a,b,c,d)
h=0.0625;tspan=[0 40];y0=[2 1];
a=1.2;b=0.6;c=0.8;d=0.3;
yp = [a*y(1)-b*y(1)*y(2);-c*y(2)+d*y(1)*y(2)];
[t y] = eulersys(@predprey,tspan,y0,h,a,b,c,d);
subplot(2,2,1);plot(t,y(:,1),t,y(:,2),'--')
legend('prey','predator');title('(a) Euler time plot')
subplot(2,2,2);plot(y(:,1),y(:,2))
title('(b) Euler phase plane plot')
[t y] = rk4sys(@predprey,tspan,y0,h,a,b,c,d);
subplot(2,2,3);plot(t,y(:,1),t,y(:,2),'--')
title('(c) RK4 time plot')
subplot(2,2,4);plot(y(:,1),y(:,2))
title('(d) RK4 phase plane plot')
end
Not enough input arguments.
Error in predprey (line 6)
yp = [a*y(1)-b*y(1)*y(2);-c*y(2)+d*y(1)*y(2)];

採用された回答

Adam Danz
Adam Danz 2021 年 6 月 5 日
編集済み: Adam Danz 2021 年 6 月 8 日
yp = [a*y(1)-b*y(1)*y(2);-c*y(2)+d*y(1)*y(2)];
That line assumes a, y, b, c,and d are defined.
The variables a, b, c, and d are defined in your function but y is not. You've defined a variable 'y0'; perhaps you meant to use the variable y instead.
When you call your function with less than 2 inputs (or with no inputs), you receive the error because y is not defined.
Also note that defining input variables within a function is pointless unless you're just still developing the function and want to quickly test it. Otherwise, remove the variable definitions that are input variables or place those definitions within conditions that test for missing inputs.

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by