define function and use ode45

11 ビュー (過去 30 日間)
Eunseong Jun
Eunseong Jun 2021 年 7 月 2 日
回答済み: Cris LaPierre 2021 年 7 月 2 日
Hello! Before using the ode45 solver, first I define multiple first differential equation using function.
However, I keep getting error, and do not know why I get.
function dy=transeq5(t,y)
dy=zeros(44,1);
dy(1) = - y(1)*y(5)*y(34) + y(2)*(y(41)+y(24))+ ...
y(2)*y(4)*y(36)+y(33)*y(2)*y(5)+y(2)*y(3)*y(32);
end
dy represents first derivative of y respect to t. :dy =dy/dt
I declared y values globally.
Also, I wrote dy(2),... upto dy(10). However, I attach partially where I am having troubles.
However, the error messages I receive are:
Not enough input arguments.
and
Error in transeq5 (line 5)
dy(1) = - y(1)*y(5)*y(34) +
y(2)*(y(41)+y(24))+ ...
Can you explain?
Later, I am doing:
options=odeset('RelTol',1e-5,'AbsTol',1e-5*ones(44,1));
[T,Y]=ode45(@transeq5,[0 2e-3],y);
Thank you so much!

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 7 月 2 日
It looks to me like you need to define your initial conditions for y. You say you declare them globally. You do not want to do that.
y0 = rand(1,44);
[T,Y]=ode45(@transeq5,[0 2e-3],y0);
plot(T,Y(:,1))
function dy=transeq5(t,y)
dy=zeros(44,1);
dy(1) = - y(1)*y(5)*y(34) + y(2)*(y(41)+y(24))+ ...
y(2)*y(4)*y(36)+y(33)*y(2)*y(5)+y(2)*y(3)*y(32);
end

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by