define function and use ode45

조회 수: 16 (최근 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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by