NIntegrate on a solution of a matrix ODE
As the error message says, the problem is that mat2[0.0795732]
is not numerical. It is instead a 2x2 matrix of numbers. You could do something like:
mat2[t_?NumericQ] := mat1[g, 10][t][[1,1]]
NIntegrate[mat2[t], {t, 0, 10}]
36.4662
On the other hand, it is much simpler to just have NDSolveValue
do the integration for you:
mat1[G_,tfinal_] := NDSolveValue[
{
int'[t] == u[t], int[0] == ConstantArray[0, Dimensions[G[0]]],
u'[t]==G[t].u[t], u[0]==IdentityMatrix[Dimensions[G[0]][[1]]]
},
{u, int},
{t,0,tfinal}
]
Then:
mat1[g, 10]
and:
mat1[g, 10][[2]][10]
{{36.4662, 0.}, {3.69638*10^20, 5.23821*10^20}}
agreeing with the above result.
You can use Integrate
to directly antidifferentiate an interpolating function. If $f(t)$ is an interpolating function with domain $(a,b)$, Integrate[f[t], t]
returns an interpolating function with the same domain equal to
$$\int_a^t f(\tau) \; d\tau\,.$$
To get the definite integral, plug the end point:
Integrate[mat1[g, 10][t], t] /. t -> 10
(* {{36.4662, 0.}, {3.69611*10^20, 5.23781*10^20}} *)