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.

1 Answer

From the documentation of Eigenvalues:

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

In your case, executing

• 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]]

• In my code, the formula for val[t] differs from time to time ? Is it correct to use ( = ) instead of ( := ) ? – V. Kao Feb 2 '18 at 14:13
• It depends on the input. Can you elaborate a bit more? – Anjan Kumar Feb 2 '18 at 14:24
• I used SetDelayed because the rhs, Eigenvalues[H[t]], changes with respect to time. – V. Kao Feb 2 '18 at 14:47
• 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
• Yes, but if you set v[t] = b* Sin[t] and b changes value at t = t0, then the expression will be evaluated for the initial value of b. – V. Kao Feb 2 '18 at 15:40