0
$\begingroup$

I have to calculate eigenvalues of 4 different matrices. The code I'm using is below, but essentially three out of the four are working with no problem, and one (the eigenvalues I've defined as y) are giving me a lot of trouble.

J={{1+p a, p a},{-l, 1}}
L={{1,p},{0,b}}
W={{p a,0},{0, 0}}
F={{0.9,0},{0,0.9}}
M[a_,b_,p_,l_]=Inverse[J].L
P[a_,b_,p_,l_]=Inverse[J].W
U[a_,b_,p_,l_]={{1/(1+a p+a l p),p/(1+a p+a l p)-(a b p)/(1+a p+a l p),0,0},
  {l/(1+a p+ a l p),(l p)/(1+a p+a l p)+(b (1+a p))/(1+a p+a l p),0,0},
  {0,0,1,0},{0,0,0,1}}
V[a_,b_,p_,l_]={{1,0,-((a p)/(1+a p+a l p)),0},
  {0,1,-((a l p)/(1+a p+a l p)),0},
  {1,0,0,0},{0,1,0,0}}
Quiet[B[a_,b_,p_,l_]=
  -Inverse[Take[Inverse[SchurDecomposition[{U[a,b,p,l],V[a,b,p,l]}][[3]]],{3,4},{1,2}]].
  Take[Inverse[SchurDecomposition[{U[a,b,p,l],V[a,b,p,l]}][[3]]],{3,4},{3,4}]];
Quiet[v[a_,b_,p_,l_]=Eigenvalues[M[a,b,p,l].(IdentityMatrix[2]+B[a,b,p,l])]];
Quiet[w[a_,b_,p_,l_]=Eigenvalues[KroneckerProduct[Transpose[B[a,b,p,l]],M[a,b,p,l]]+
  KroneckerProduct[IdentityMatrix[2],M[a,b,p,l].B[a,b,p,l]]]];
Quiet[y[a_,b_,p_,l_]=Eigenvalues[KroneckerProduct[F,M[a,b,p,l]]+
  KroneckerProduct[IdentityMatrix[2],M[a,b,p,l].B[a,b,p,l]],Cubics->True,Quartics->True]];
Quiet[z[a_,b_,p_,l_]=Eigenvalues[M[a,b,p,l].B[a,b,p,l]]];
v[1,.99,1,.25]
w[1,.99,1,.25]
z[1,.99,1,.25]
y[1,.99,1,.25]
Eigenvalues[KroneckerProduct[F,M[1,.99,1,.25]]+KroneckerProduct[IdentityMatrix[2],M[1,.99,1,.25].b[1,.99,1,.25]]]

So the quiets are there to ignore Mathematica flipping out about passing symbolic matrices into Schur decomposition, but B produces the same matrices that would be produced by the expression if given a set of parameter values. When I call v,w, and z with parameter value inputs I get an expected results, but when I call y as above I get 16 eigenvalues instead of 4. When I leave cubics and quartics off it gives me the following error:

Root::npoly: {{5.25119 -1.3353 #1+0.114118 #1^2-0.0037085 #1^3+0.0000342936 #1^4,
1.1164-0.359741 #1+0.0413553 #1^2-0.00199383 #1^3+0.0000342936 #1^4,<<1>>,
1.1164 -0.359741 #1+0.0413553 #1^2-0.00199383 #1^3+0.0000342936 #1^4},
<<2>>,{<<1>>,<<1>>,<<1>>,<<1>>}} is not a polynomial in #1. >>

Three times. The values it does return after these errors are long expressions (i.e. it abridges the output) and it features a lot of multiplication of real numbers that hasn't been evaluated.

I also have evaluated the expression for y with the same set of parameter values and it gives me a simple set of four eigenvalues.

Hopefully this makes sense, I've spent a day scouring the internet to see if someone else has run into a similar problem and found nothing. Any help is greatly appreciated.

Edit: Realized that v is giving similar issues, giving me 8 values instead of 2. When I just evaluate the expression with the same parameter values it gives me 2 like it should.

$\endgroup$

closed as off-topic by MarcoB, user9660, m_goldberg, Öskå, ubpdqn Jun 21 '16 at 8:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Community, m_goldberg, Öskå, ubpdqn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ your code has syntax errors in it, see def. of v. Also you can't use patterns like a_,b_,p_,l_ on the right side of your assignments. $\endgroup$ – Jens Jun 16 '16 at 19:19
  • $\begingroup$ That was a transcription error (re: a_,b_,p_,l_) $\endgroup$ – Ben Jun 16 '16 at 19:55
2
$\begingroup$

Your error is in the fact you don't delay your function. You run the Eigenvalues based on M with [a,b,p,l] as variables. Please amend your code by adding a : before the =. This ensures that the actual calculations aren't done until you call them. Now you also don't need the quiets.

v[a_, b_, p_, l_] := 
  Eigenvalues[M[a, b, p, l].(IdentityMatrix[2] + B[a, b, p, l])]
v[1, .99, 1, .25]

{1.32892, 0.662193}

y[a_, b_, p_, l_] := 
   Eigenvalues[
    KroneckerProduct[F, M[a, b, p, l]] + 
     KroneckerProduct[IdentityMatrix[2], M[a, b, p, l].B[a, b, p, l]],
     Cubics -> True, Quartics -> True];
y[1, .99, 1, .25]

{1.24153, 1.24153, 0.606027, 0.606027}

$\endgroup$
  • $\begingroup$ Ah thanks so much. $\endgroup$ – Ben Jun 16 '16 at 21:06

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