TransWikia.com

How can I use Tally in my code?

Mathematica Asked on June 28, 2021

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 {2pi^2,, 5pi^2,, 5pi^2,, 8pi^2,, 10pi^2,, 10pi^2,, 10pi^2,, 10pi^2 }$.

Now I want to use Tally to find the multiplicity of a specific eigenvalue (for example, take the eigenvalue $5pi^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.

Please help me.

One Answer

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}$.

enter image description here


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

enter image description here


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

enter image description here


Also Wolfram mentions this in his documentation.

enter image description here

Correct answer by Conor Cosnett on June 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP