define function and use ode45
이전 댓글 표시
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개)
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
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
