0
$\begingroup$

I need to create a function with the Eigenvalues output. The problem in question is that I need to manipulate variables from the eigenvalues and then plotting them. A simple version of the problem is

u = 
  (Exp[I*Phi]/Sqrt[2]) * 
    ({{Exp[I*Pi*(l + m)/4], Exp[-I*Pi*m/2]*Exp[I*Pi*(l + m)/4]}, 
      {-Exp[I*Pi*m/2]* Exp[-I*Pi*(l + m)/4], Exp[-I*Pi*(l + m)/4]}})

with the eigenvalues

eigenval = Eigenvalues[u]
{(E^(I*Phi - (I*m*Pi)/2 - (1/4)*I*(l + m)*Pi) *
  (E^((I*m*Pi)/2) + E^((I*m*Pi)/2 + (1/2)*I*(l + m)*Pi) - 
   E^((I*m*Pi)/2)*Sqrt[1 - 6*E^((1/2)*I*(l + m)*Pi) + 
   E^(I*(l + m)*Pi)]))/(2*Sqrt[2]), 
 (E^(I*Phi - (I*m*Pi)/2 - (1/4)*I*(l + m)*Pi)*
  (E^((I*m*Pi)/2) + E^((I*m*Pi)/2 + (1/2)*I*(l + m)*Pi) + 
   E^((I*m*Pi)/2)*Sqrt[1 - 6*E^((1/2)*I*(l + m)*Pi) + 
   E^(I*(l + m)*Pi)]))/(2*Sqrt[2])}

I tried to define functions from the eigenvalue output like so:

ein1[m_, l_, phi_] := eigenval[[1]]
ein2[m_, l_, phi_] := eigenval[[2]]

The problem is that if a change the values as ein[1, 2, 3], there is no substitution in eigenval[[1]]. So I ended doing this substitution by hand, but I need to manipulate a large number of eigenvalues and that besides to be a tedious task, it leads to a large number of "human errors". Do you know if there is an efficient method to do this?

$\endgroup$

1 Answer 1

4
$\begingroup$

:= delays evaluation, so eigenval[[1]] gets evaluated after the substitution. Thus, the substitution has no effect. In this case, you should use =:

ein1[m_,l_,phi_]= eigenval[[1]]
ein2[m_,l_,phi_]= eigenval[[2]]

This will evaluate the right hand sides when you create the definitions, before you use them. Thus, the substitution will occur.

$\endgroup$

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