0

The equations looks like this:

dxi(t)/dt = -c * xi(t) * yi(t)

dyi(t)/dt = a * Σ{i=1 to n}(xi(t) * yi(t)) + xi(t) * yi(t - 1) + b

where a, b and c are whatever constant values you want, for example a=1, b=2, c=3.

Σ{i=1 to n}(xi(t) * yi(t)) means summation from i=1 to n, for example n=3: x1(t)*y1(t) + x2(t)*y2(t) + x3(t)*y3(t)

So, how can I express & solve this using matlab?

JZ555
  • 617
  • 2
  • 7
  • 16
  • 1
    Did you check out http://www.mathworks.com/help/symbolic/solve-a-system-of-differential-equations.html ? – Franck Dernoncourt Apr 14 '13 at 17:10
  • Yes, but I don't think it's possible to solve it with dsolve because there's term like this in the second equation: xi(t) * yi(t - 1). – JZ555 Apr 14 '13 at 17:56

2 Answers2

1

You need to build what is called a delayed differential equation. I was about to explain how to do, but then I found this wonderful tutorial to do just that. Example 1 is basically what you need.

The only extra caveat is that you should incorporate dx/dt and dy/dt into the same set of differential equation

Let me know if you need more help

Edit: keep it in one file

function  dYdt = ddefun(t,Y,Z)
    % assume Y = [x;y]
    x = Y(1:n); % 2n is the size of Y. this step is unnecessary ...
    y = Y(n+1:2*n); % but helps visualize what is happening

    ytau = Z(:,1);

    dYdt(1:n) = -c*x.*y;
    dYdt(n+1:2*n) = a*dot(x,y) + x.*ytau + b

end
Rasman
  • 5,349
  • 1
  • 25
  • 38
  • Thanks. I did some research on these delayed differential equations and found another example here: http://matlab.cheme.cmu.edu/tags/delay-differential-equation/ – JZ555 Apr 15 '13 at 05:51
  • In that example you don't actually have to incorporate the equations into the same set. So, what I have to do, is to create a history function that gives me the past values of xi and yi. Now the only problem is how I create the summation inside the function that includes my dde? – JZ555 Apr 15 '13 at 06:00
  • @user2280026 Since the equations are intertwined, you should incorporate the equations into the same set. What you then do is a [dot](http://www.mathworks.com/help/matlab/ref/dot.html) product on the variables. Don't overthink your problem: see edit above – Rasman Apr 15 '13 at 11:36
  • Thanks. That was very helpful. But I'm wondering if the dimensions are correct in your code. First of all, is Y row or column matrix? If it's row: let's say Y = [1,2,3; 4,5,6]. Then I do x = Y(1:3) (since n=3). Now I have x = [1,4,2] when the x values actually were 1,2 and 3, also y = [5,3,6] instead of 4,5 and 6. – JZ555 Apr 16 '13 at 08:20
  • @user2280026 both Y and dYdt are one dimensional matrices, usually a column vector – Rasman Apr 16 '13 at 12:45
  • Ok. Now, when I run my program, it says that matrix dimensions must agree on the second (dYdt(n+1:2*n) = a*dot(x,y) + x.*ytau + b) equation. Propably because ytau is now 2nx1 matrix and x is nx1 matrix. So I changed the code so that ytau = Z(n+1:2*n). Is this correct? Also it said that dde must return column vectors and right now your code gives row vectors. So I did like this: dxdt = -c*x.*y; dydt = a*dot(x,y) + x.*ytau + b; dYdt = [dxdt; dydt]; – JZ555 Apr 17 '13 at 07:19
0

If you're looking for a numerical solution (which means you need initial conditions also), the most common solver used is ode45. The link gives examples on how to express specific ODEs.

Later Edit: For the term yi(t−1) you may want to integrate your function in "chunks" of length 1 for t — e.g. t ∈ { [0,1], [1,2], [2,3]... } — and using the previously found solution as coefficient in the actual time "chunk." Like this the solutions "feed" from themselves, and you won't be bothered by the convolution. Of course, one needs to consider yi(t−1) = 0 (or other known function) in the initial iteration.