필터 지우기
필터 지우기

solving 2 ODE's - problem with ode45 initial conditions

조회 수: 2 (최근 30일)
Daniel
Daniel 2013년 4월 26일
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])

답변 (2개)

Zhang lu
Zhang lu 2013년 4월 26일
편집: Zhang lu 2013년 4월 26일
x0 and y0 must be one input , can't be a vector.
  댓글 수: 1
Daniel
Daniel 2013년 4월 26일
the initial condition can be a vector (I saw it in MATLAB help), but I guess only a row vector?

댓글을 달려면 로그인하십시오.


Jan
Jan 2013년 4월 26일
편집: Jan 2013년 4월 26일
x0 is the initial time, 1 in your case according to the time interval [1, 100]. When you want t0 = 0, you need [0, 100].
Now y0 must be a [2 x 1] vector with the initial position. I cannot understand, why there are 4 initial values in your case, but you need 2 only.
  댓글 수: 1
Daniel
Daniel 2013년 4월 26일
편집: Daniel 2013년 4월 26일
The problem is that the initial conditions I have are [5,2] for y(1) (x(t)) and [2,10] for y(2) (y(t)), so that's why I tried four initial conditions. But in reference to what you're saying, I guess the problem is that I have two initial conditions that occur at different times (t=5 and t=2)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by