Beginner Coding: Counting number of states

Hi,
This is my first time coding with any program, and I have a "logistical" question about how to code something to count the number of states?
So the problem that I have to solve is finding the way that 5 particles can be distributed in to 0:5 energy levels given that the total energy can only be from 0-8. So what the question requires me to find is how many ways I can get one energy configuration (let's say total energy equally 4). what I've done so far is that I have made 5 loops - a=[0:5], b=[0:5], c=[0:5], d=[0:5], e=[0:5]. and so is there a function in matlab that can allow me to count how ways I can get a+ b+ c+ d+ e =4?

Respuestas (1)

Image Analyst
Image Analyst el 20 de Mzo. de 2015
Not a function, but just store the number
theSum = 0; % Initialize
Then your 5 for loops, and in the middle of those
if a+b+c+d+e == 4
theSum = theSum + 1;
end

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Mzo. de 2015

Respondida:

el 20 de Mzo. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by