Student201
Student201

Reputation: 45

System of ODEs in matlab

I am not sure how to implement the following system of ODEs as a single function on Matlab:

dy/dt = y(t) - y(t)x(t)

dx/dt = -x(t) + y(t)x(t)

Any help would be much appreciated as been stuck on this part of my overall problem for ages. Thanks

Upvotes: 3

Views: 150

Answers (2)

Lutz Lehmann
Lutz Lehmann

Reputation: 26040

Up to defining the constants to use, it should look like this:

function dzdt = odefunc(t,z) 
    x = z(1); y=z(2);
    dzdt = [ -x + x*y;  y - x*y ];
end

T, Z = ode45(odefunc, [T0  Tf], [ x0; y0 ])

As

F(x,y) = x+log(1/x) + y+log(1/y)

is a first integral with bounded level sets, the solutions will stay bounded (and are periodic) for positive initial values x0,y0.

Upvotes: 4

percusse
percusse

Reputation: 3106

If you are not versed in the command line tools to create and simulate ODEs, then just use Simulink and then try to manipulate models from command line via lsim and then finally try to create the models in m files.

Here is a 2-minute exercise in simulink which allows you to choose whichever solver you like from a dropdown list.

enter image description here

Upvotes: 0

Related Questions