define function and use ode45
조회 수: 16 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
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
댓글 수: 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!
