I have the following matrix:

  M = {{En + 2 Cos[k a] t, t1 + t2 Cos [k a]},{t1 + t2 Cos [k a], En + 2 Cos[k a] t}};

I want the eigen value to be function of t,t1 and t2 so that they can be manipulated: So I do the following:

  eg[t1_, t_, t2_] := eig[[1]];

But in the information of eg, it shows:


But if I print out eig and copy the expression in

eg[t1_,t_,t2_]:=En - t1 + 2 t Cos[a k] - t2 Cos[a k];(*The expression of eig[[1]]*)

I get what I want. Could someone explain me where I am going wrong and how to get it correct without the copy pasting.


1 Answer 1


There are two options:

eg[t1_, t_, t2_] := Evaluate[eig[[1]]]


eg[t1_, t_, t2_] = eig[[1]]

The reason for this is eig needs to be evaluated before the function is called with the arguments. If you use SetDelayed, the eig[[1]] remains unevaluated until the function is called. Let me illustrate.

fun = {x + 1, y};
f[x_] := fun[[1]];
g[x_] = fun[[1]];






Let's Trace

f[2] // Trace
g[2] // Trace



So, as you see, f ignores the argument since pattern matching of the argument to the RHS is done first in a function call, but fun as a symbol doesn't match to x_. The RHS is then evaluated, but by the time x appears, the pattern matching was over. In the case of g, the RHS contains x, so the argument is matched and the whole expression is evaluated with the new value. Instead of Setyou can force evaluate the RHS using Evaluate.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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