solving 2 ODE's - problem with ode45 initial conditions
3 次查看(过去 30 天)
显示 更早的评论
dx/dt=x(3-x-2y) dy/dt=y(2-x-y)
I'm trying to solve the two ODE's above and am struggling. Is it possible to solve them as two separate functions with two separate ode45 commands? I am under the impression that that is not possible, so I've combined them into one function like this:
function df=odefunc(t,f)
% function f represents both x(t) and y(t) as a system
df=zeros(2,1);
df(1)=f(1)*(3-f(1)-2*f(2)); %f(1)=x(t) ; df(1)=dx/dt
df(2)=f(2)*(2-f(1)-f(2)); %f(2)=y(t) ; df(2)=dy/dt
end
But then my other issue is that my initial conditions aren't at time t=0. They are x0=[5,2] and y0=[2,10]. So when I ran the ode45 command below, I got an error message regarding the initial conditions. Any help is appreciated-thanks!
[T,fXY]=ode45(@odefunc,[1,100],[5,2;2,10])
0 个评论
回答(2 个)
另请参阅
类别
在 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!