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?

답변 (1개)

Image Analyst
Image Analyst 2015년 3월 20일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2015년 3월 19일

답변:

2015년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by