Say I have an expression
g = x^2 + y^3;
I tried writing this
H[x_, y_] := Eigenvalues[Evaluate[{{0, g}, {g, 0}}]];
The behaviour I am trying to achieve is that when I write H[2,3]
it will substitute x->2
and y->3
inside the matrix and then evaluate Eigenvalues
. I do not want Eigenvalues
to be evaluated before calling H[x,y]
because in general it is much more efficient to calculate the numerical eigenvalues rather than symbolic and then substituting. How can I achieve this behaviour? I don't want to do something ugly like
H[xx_, yy_] := Eigenvalues[{{0, g}, {g, 0}} /. {x -> xx, y -> yy}]
I would like to keep using the same variable names in an intuitive way