Error report when using ode45 function

6 ビュー (過去 30 日間)
Erin Sausage
Erin Sausage 2021 年 2 月 20 日
コメント済み: Erin Sausage 2021 年 2 月 21 日
The following errors occurred in solving the tripartite evolutionary game,does anyone know the reason?
Here is the error.
索引超出矩阵维度。
出错 differential (line 2)
dxdt=[x(1)*(1-x(1))*(10-3*x(3)-5*x(2));x(2)*(1-x(2))*(4*x(1)+12.6*x(3)-9);
出错 odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
出错 ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
出错 run (line 5)
[T,Y]=ode45(@differential,[0,20],[i j m]);
The code is as follows.
function dxdt=differential(x,t)
dxdt=[x(1)*(1-x(1))*(10-3*x(3)-5*x(2));x(2)*(1-x(2))*(4*x(1)+12.6*x(3)-9);
x(3)*(1-x(3))*(3*x(1)*x(2)+20.4*x(2))]
%t是演化的步长和时间
end
--------------------------------------
clear all
for i=0.1:0.2:0.9
for j=0.1:0.2:0.9
for m=0.1:0.2:0.9
[T,Y]=ode45(@differential,[0,20],[i j m]);
figure(1)
grid on
plot(T,Y(:,1),'r-','lineWidth',1);
hold on
plot(T,Y(:,2),'b--','lineWidth',1);
hold on
plot(T,Y(:,3),'g*','lineWidth',1);
hold on
end
end
end
  2 件のコメント
James Tursa
James Tursa 2021 年 2 月 20 日
Please delete these images and instead post your code and error messages as text highlighted with the CODE button. We can't copy & run pictures.
Erin Sausage
Erin Sausage 2021 年 2 月 21 日
Oh thanks for reminding me. I re-edit the post as you say, if possible, could you plz help me to see why such the error occurs?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 21 日
function dxdt=differential(x,t)
needs to be
function dxdt=differential(t,x)
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 21 日
No, versions would not have anything to do with it. The code was just wrong. In order to use that function the way it was, you would need to use
[T,Y]=ode45(@(t,x)differential(x,t), [0,20], [i j m]);
Erin Sausage
Erin Sausage 2021 年 2 月 21 日
I see. I'm so greatful for your reply!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber games についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by