# problem with (numerical) integration

The (simplified) matrix I use is the following:

H[t_] := {{34,
Piecewise[{{0, t < 3.4}, {0.7*(t - 3.4),
t >= 3.4}}]}, {Piecewise[{{0, t < 3.4}, {0.7*(t - 3.4),
t >= 3.4}}], 1}}


and the eigenvalues are:

v[t_] := Eigenvalues[H[t]];


I want to integrate (numerically) the eigenvalues, but the result is wrong. I found out that the problem is:

v[t] /. t -> 1 gives {1, 34}

v[1] gives {34, 1}


Can anyone help me solve this problem ? In fact I have to evaluate the integral of the eigenvalues of a 12x12 matrix.

From the documentation of Eigenvalues:

If they are numeric, eigenvalues are sorted in order of decreasing absolute value.

• v[1] means EigenValues takes numeric arguments, thus the sorting in the output.
• v[t]/.t->1 takes the symbolic eigenvalues and then replaces t with 1, thus no sorting.
To avoid that you may use Set (=) (atleast for this case) for the definition of v[t]
v[t_] = Eigenvalues[H[t]]

• Usually, function definitions use SetDelayed, but in some cases you can use Set. For example, v[t] = Sin[t] works similar to v[t]:= Sin[t]. Check the discussion: mathematica.stackexchange.com/questions/8829/… – Anjan Kumar Feb 2 '18 at 15:00