I am having trouble trying to solve a differential equation which couples the elements of a matrix. Let's say I have the following
NDSolve[{D[rho[t],t] == f[rho, t], rho[0]==rho0}, rho, {t, 0, 1}]
with f[rho, t]
some function of the matrix rho
and time. If this function just involves built-in operations on matrices (e.g. Dot
product with another matrix) everything is fine. For example, I can successfully solve the system with
f[rho_,t_]:=Dot[rho,M]Cos[t]
where M
is a random matrix of the same dimensions of rho
. The problem arises when I try to access the components of the matrix. When I define the following function
f[rho_,t_]:=Table[rho[[n,m]],{n,1,2},{m,1,2}]Cos[t]
NDSolve
gives me the error message
Part specification rho[t][[0,1]] is longer than depth of object.
(and the same for the other indices). I assume that the all the built-in functions manipulate lists in a different way. What am I suppose to do?
P.s.: The real problem is much more complicated than this. I would not be able to explicitly write the equation for each matrix element.