0
$\begingroup$

This is simplified version of my real code:

mat[x_] := {{x^2, 1, 0}, {1, x^2, -1}, {0, -1, x}}
ei[x_] := Eigensystem[
    mat[x],
    1,
    Method -> {"Arnoldi", "Criteria" -> "RealPart"}
    ][[1, 1]]
NIntegrate[ei[x], {x, 0, 4}]

and Mathematica gives me this error:

Eigensystem::arm: Method -> Arnoldi can only be used for matrices of machine- or arbitrary-precision real numbers. 

I tried changing WorkingPrecision of NIntegrate, fixing the precision, and changing the code to:

mat[x_] := SetPrecision[{{x^2, 1, 0}, {1, x^2, -1}, {0, -1, x}}, 20]
ei[x_] := Eigensystem[
    SetPrecision[mat[N[x, 20]], 20],
    1,
    Method -> {"Arnoldi", "Criteria" -> "RealPart"}
    ][[1, 1]]
NIntegrate[ei[N[x, 20]], {x, 0, 4}, WorkingPrecision -> 20]

Still did not help. Why this is happening?

I need to use Arnoldi method to find the eigenvalues and eigenvectors, since my real matrix is very big and I am interested in couple of eigenvalues and eigenvectors.

$\endgroup$
  • 1
    $\begingroup$ You need to insert x_?NumericQ somewhere in your definitions to thwart the attempt at symbolic preprocessing. $\endgroup$ – J. M. is in limbo Jun 11 '16 at 15:58
  • $\begingroup$ @J.M., I have changed the declarations of the variables in the functions with x_?NumericQ, as well as added the option: Method -> {Automatic, "SymbolicProcessing" -> False}. Did not help, I am still getting the error. $\endgroup$ – gurluk Jun 11 '16 at 16:04
  • $\begingroup$ Are the values you're getting with this actually correct though? $\endgroup$ – Feyre Jun 11 '16 at 16:57
  • $\begingroup$ @Feyre, you mean eigenvalues, or the result of the integration? $\endgroup$ – gurluk Jun 11 '16 at 17:00
  • 3
    $\begingroup$ @gurluk: part of your problem is that you are thinking in terms of "declarations", a concept from other programming systems. This is foreign to Mathematica. x_NumericQ is not a declaration, but a constrained pattern, a very different beast. $\endgroup$ – John Doty Jun 11 '16 at 17:16
5
$\begingroup$
mat[x_?NumberQ] := {{x^2, 1, 0}, {1, x^2, -1}, {0, -1, x}}
ei[x_] := 
 Eigensystem[mat[x], 1, 
   Method -> {"Arnoldi", "Criteria" -> "RealPart"}][[1, 1]]
NIntegrate[ei[x], {x, 0, 4}]

(* 8. *)

$\endgroup$
  • $\begingroup$ This does not get rid of the error message, nor change anything. $\endgroup$ – Feyre Jun 11 '16 at 17:02
  • $\begingroup$ It worked for you? :) What? I am copying the same code and it still gives the same error? haha $\endgroup$ – gurluk Jun 11 '16 at 17:02
  • 3
    $\begingroup$ This works. For those who say it doesn't (@Feyre) : probably you forgot to clear your old definitions of mat that don't contain the restriction! So I'd suggest adding Clear[mat] in front of the answer. $\endgroup$ – Jens Jun 11 '16 at 17:09
  • $\begingroup$ @rewi, now works. $\endgroup$ – gurluk Jun 11 '16 at 17:13
  • $\begingroup$ @Jens, I cannot believe the problem was actually so small and easy. I was expecting something related to arbitrary precision, I think I overthought :) Thank you both. $\endgroup$ – gurluk Jun 11 '16 at 17:13

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.