I want to define a vector PosVec[a, b]
dependent on the variables a
and b
of a matrix VecMat[a, b]
. I want to calculate the "positions" in VecMat[a, b]
of the maximum values in VecMatQ[a, b]
and store them in PosVec[a, b]
.
My problem is that, with my code below, I can't access the variables a
and b
of PosVec
by PosVec[a, b] -> PosVec[1, 1]
For the positions in VecMatQ
where there are entries of a
and b
, Position
generates empty spaces as shown below:
Here is my code:
Remove["Global`*"]
m = {{1, -a + b, 3}, {b, -6, 4}, {3, b, 0}};
VecMat[a_, b_] = Eigenvectors[m];
VecMatQ[a_, b_] = VecMat[a, b]*Conjugate[VecMat[a, b]];
PosVec[a_, b_] =
Table[Position[VecMatQ[a, b][[i]], Max[VecMat[a, b][[i]]]], {i, 1, 3}] // Flatten;
PosVec[1, 1]
{{},{},{}}
but
Table[Position[VecMatQ[1, 1][[i]], Max[VecMat[1, 1][[i]]]], {i, 1, 3}] // Flatten
gives the right values
{(3),(2),(1)}
Can someone help me to make the evaluation of Position
dependent on the variables a
and b
?
PosVec[a_, b_] =
toPosVec[a_, b_] :=
, i.e. useSetDelayed
instead ofSet
. Longest (but cleaner I think) way: change allSet
toSetDelayed
, definem
as a two-args function, and modify the right-hand side of your second definition accordingly. $\endgroup$SetDelayed
instead ofSet
when for instance a definition involves parameters (so regardingm
, defining it asm := {{1, -a + b, 3}, {b, -6, 4}, {3, b, 0}}
). Ifa
andb
were to have values before definingm
, the definition ofm
won't be affected, which is not the case when using aSet
. $\endgroup$Set
andSetDelayed
is this post. $\endgroup$