# How can I use Tally in my code?

I a computing the eigenvalues and eigenfunctions of a Laplacian on a unit square. I have written it as follows:

{ℒ, ℬ} = {-Laplacian[u[x, y], {x, y}],DirichletCondition[u[x, y] == 0, True]};
{vals, funs} = DEigensystem[{ℒ, ℬ}, u[x, y], {x, 0, 1}, {y, 0, 1}, 8];
vals


Therefore, I have received the list of first $$8$$ eigenvalues, that is:

$$\qquad \{2\pi^2,\, 5\pi^2,\, 5\pi^2,\, 8\pi^2,\, 10\pi^2,\, 10\pi^2,\, 10\pi^2,\, 10\pi^2 \}$$.

Now I want to use Tally to find the multiplicity of a specific eigenvalue (for example, take the eigenvalue $$5\pi^2$$). I have no idea how to use Tally within the code written above. Please help me. I have read the reference here, but I have no idea how to use it in my case.

• take a look at mathematica.stackexchange.com/questions/183096/… Commented Feb 14, 2021 at 8:57
• In general, I think Counts and CountsBy are more useful functions than Tally. Tally is a bit of a relic of the past. Commented Feb 14, 2021 at 15:20

Tally can certainly count the occurrances of eigenvalues in your list called vals. For instance Tally[vals] tells me that there are $$2$$ instances of $$10 \pi^{2}$$ and $$2$$ instance of $$5 \pi^{2}$$.

Looking at Tally in the documentation I see that the word "multiplicities" means the number of instances of each distinct element in a list.

I notice that your code is producing a different vals in my notebook! Please quit your kernel and re-evaluate!

Also Wolfram mentions this in his documentation.

• Thanks for your answer. Actually I want to know the multiplicity of a specific eigenvalue $5 \pi^2$. By "Multiplicity" I mean the dimension of eigenspace (number of linearly independent eigenvectors corresponding to the specific eigenvalue). Are the the multiplicity of an eigenvalue and "Tally" same things?
– user81126
Commented Feb 14, 2021 at 6:35
• sorry, I'm in a zoom meeting now. I'll get back to you in 2 hours. (maybe have a look at Thread[{funs, vals}]) Commented Feb 14, 2021 at 6:42
• Upon reading different sources on google I'm $90$% certain that the "multiplicity" of $5\pi^{2}$ is $2$. Commented Feb 14, 2021 at 9:12
• Thanks for your advise, but I have some confusions that whether the "multiplicity" in the mathematica documentation same as the "multiplicity" defined in linear algebra (i.e. here by "multiplicity" we mean dimension of eigenspace or number of linearly independent eigenvectors corresponding to the specific eigenvalue or please see the link). Can you please help me?
– user81126
Commented Feb 14, 2021 at 10:09
• Thanks for your link. But my confusions is still there.Your link gives the idea about number of occurrence of a specific eigenvalue in the eigenvalue list. But, it does not tell about my confusions. My question is as follows: $\textbf{Is the "multiplicity" in the mathematica documentation same as the "multiplicity" defined in linear algebra (i.e. here by "multiplicity" we mean dimension of eigenspace or number of linearly independent eigenvectors corresponding to the specific eigenvalue)?$
– user81126
Commented Feb 14, 2021 at 11:07