I have the following code producing an interpolated unitary matrix:
H[t_] := PauliMatrix[3] + Cos[t]*PauliMatrix[1];
sol = First[NDSolve[{I*D[matU[s],s] == H[s].matU[s],matU[0] == IdentityMatrix[2]}, matU, {s, 0, 20}]];
mU = matU /. sol;
This produces the unitary matrix mU which I can use as a function. For example, writing mU[4] gives a matrix.
However, if I want to integrate this, for example writing NIntegrate[mU[t], {t, 1, 5}] it does not work. It says
NIntegrate: Integrand InterpolatingFunction[{{0.,20.}},{5,3,1,{282},{4},0,0,0,0,Automatic,<<3>>},{{<<1>>}},{{{{1. +0. I,0. +0. I},{0. +0. I,1. +0. I}},{{0. -1. I,0. -1. I},{0. -1. I,0. +1. I}}},<<9>>,<<272>>},{Automatic}][t] is not numerical at {t} = {1.00015}.
The first question is: how do I do this integral?
Second part: I use the unitary matrix to define time-dependent vectors as follows,
vec = {0, 1};
vect[t_] := mU[t].vec;
ρ[t_] := Outer[Times, vect[t], vect[t]\[Conjugate]];
Then, I try to integrate using NIntegrate[ρ[t], {t, 1, 5}] and I get two different errors:
Outer: Heads Conjugate and Dot at positions 3 and 2 are expected to be the same.
NIntegrate: Integrand Outer[Times,<<1>>,Conjugate[InterpolatingFunction[{{0.,20.}},{5,3,1,{282},{4},0,0,0,0,Automatic,<<3>>},{{0.,<<9>>,<<272>>}},{{{{<<2>>},{<<2>>}},{{<<2>>},{<<2>>}}},{{{<<2>>},{<<2>>}},{{<<2>>},{<<2>>}}},<<8>>,<<272>>},{Automatic}][t].{0,1}]] is not numerical at {t} = {1.00015}.
Why do I get these errors and how can I avoid them?
Thanks everybody for the help!
Edit1:
When Integrate is directly applied to the original interpolated matrix it seems to work. Therefore, the value of NIntegrate[ρ[t], {t, 1, 5}] can be obtained as follows.
First, we make Mathematica numerically solve the differential equation for ρ:
solρ = First[NDSolve[{I*D[ρS[s], s] ==
H[s].ρS[s] - ρS[s].H[s], ρS[0] ==
Outer[Times, vec, vec]}, ρS, {s, 0, 20}]];
ρt = ρS /.solρ;
Then, we can integrate it using Integrate[ρt[t], {t, 1, 5}].
However, if we try to compute Integrate[Sin[t]*ρt[t], {t, 1, 5}] or even Integrate[Sin[t]+ρt[t], {t, 1, 5}] we do not get any number as output (but we also do not get error messages).
The same numerical result can be obtained with the following code which follows the one given in an answer:
vect2[t_, i_] := mU[t][[i, 2]];
ρ2[t_, i_, j_] := vect2[t, i]*vect2[t, j]\[Conjugate];
Table[NIntegrate[ρ2[t, i, j], {t, 1, 5}], {i, 2}, {j, 2}]
When using this, Mathematica does complain a bit but arrives at the same result up to 10^(-7).
Moreover, with this code we can calculate the following Table[NIntegrate[Sin[t]*ρ2[t, i, j], {t, 1, 5}], {i, 2}, {j, 2}].
However, this code seems quite a workaround, which I would prefer to avoid in more complex situations.

Integrate[mU[t], {t, 1, 5}]It looks like Integrate can deal with matrices, but NIntegrate can not. – Daniel Huber Dec 29 '21 at 17:24mU[t]but still does not work for\[Rho][t]. – Knomes Dec 29 '21 at 17:30NIntegrateon arrays): (34554), (126001) – Michael E2 Dec 31 '21 at 04:46