define function and use ode45
11 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Cris LaPierre
on 2 Jul 2021
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 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!