0
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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]]
| improve this answer | |
$\endgroup$
  • $\begingroup$ In my code, the formula for val[t] differs from time to time ? Is it correct to use ( = ) instead of ( := ) ? $\endgroup$ – V. Kao Feb 2 '18 at 14:13
  • $\begingroup$ It depends on the input. Can you elaborate a bit more? $\endgroup$ – Anjan Kumar Feb 2 '18 at 14:24
  • $\begingroup$ I used SetDelayed because the rhs, Eigenvalues[H[t]], changes with respect to time. $\endgroup$ – V. Kao Feb 2 '18 at 14:47
  • $\begingroup$ 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/… $\endgroup$ – Anjan Kumar Feb 2 '18 at 15:00
  • $\begingroup$ 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. $\endgroup$ – V. Kao Feb 2 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.