# How to solve the integro differential equations with matrix

I have integro-differential equations like

$X'(t)=\operatorname{diag}(\int_0^t X(t) dt)AX(t)-X(t)$,

where $A$ is a known $N\times N$ matrix and $X$ is a $N\times 1$ vector, and $\operatorname{diag}$ means constructing a diagonal matrix from a vector.

I have no idea about how to represent a vector variable in Mathematica and how to program to solve the equations.

• As Jim Baldwin said this question needs more clarity and examples. For example, knowing -- or imposing -- the shape of the matrix $X$ and function forms in the matrix $X$ can make the equation easy to program. What is the definition of "$diag$" -- it gives a diagonal matrix or a vector of the diagonal? What is the definition of the "$*$" operator -- standard matrix (and matrix-vector) multiplication, matrix element-wise multiplication? – Anton Antonov May 28 '17 at 16:19

This answer does not produce solutions of OP's equation, but it does show how to deal with a similar matrix equation.

NDSolve can handle equations given with matrices, but in this answer I am showing the generation of a list of equations corresponding to the original matrix one.

First we introduce the functions to be found:

n = 4;
funcs = Table[ToExpression["f" <> ToString[i]], {i, n}];
X = Through[funcs[t]]

(* {f1[t], f2[t], f3[t], f4[t]} *)

dX = D[X, t]

(* {Derivative[f1][t], Derivative[f2][t],
Derivative[f3][t], Derivative[f4][t]} *)


Here we define the vector of integral functions -- F[_,_] will be replaced below.

iX = F[#, t] & /@ funcs

(* {F[f1, t], F[f2, t], F[f3, t], F[f4, t]} *)


Obtain a random matrix for A:

SeedRandom
A = RandomChoice[Exp[-Range[0, 6]] -> Range[0, 6], {n, n}];
A = Rescale[A + DiagonalMatrix[ConstantArray[1, n]]];
MatrixForm[A] Form the equations:

eqs = Thread[dX == DiagonalMatrix[iX].A.X - X];


Next ideally we will do this:

eqs = eqs /. F[f_, t_] :> Integrate[f[x], {x, 0, t}];


or this:

eqs = eqs/.F[f_,t_] :> (t (f[t]+f)/2);


(Approximation of the integral using Trapezoidal formula.)

But since NDSolve can deal with constant delays only, we are going to use this replacement rule:

eqs = eqs/.F[f_,t_] :> (t (f[t]-f[t-1])/2);

ColumnForm[eqs] Define initial conditions:

initConds = Thread[Through[funcs[t /; t <= 0]] == 1]

(* {f1[t /; t <= 0] == 1, f2[t /; t <= 0] == 1, f3[t /; t <= 0] == 1, f4[t /; t <= 0] == 1} *)


Find the solution:

NDSolve[Join[eqs, initConds], funcs, {t, 0, 10}] 